buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#dj 16D8101012J ito jun import sys def search(a,b): na=len(a) nb=len(b) array = [[0]*(nb+1) for _ in range(na+1)] for i in range(na): array[i][0]=i for j in range(nb): array[0][j]=j for i,x in enumerate(a,1): prerow=array[i-1] row=array[i] for j,y in enume...
def search(a,b): na=len(a) nb=len(b) array = [[0]*(nb+1) for _ in range(na+1)] for i in range(na+1): array[i][0]=i for j in range(nb+1): array[0][j]=j for i,x in enumerate(a,1): prerow=array[i-1] row=array[i] for j,y in enumerate(b,1): if x == ...
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
192
6
a = list(input()) b = list(input()) if len(a) == 0 or len(b) == 0: print(max(len(a),len(b))) else: dp = [[None for i in range(len(b)+1)] for j in range(len(a)+1)] for i in range(len(a)+1): dp[i][0] = i for i in range(len(b)+1): dp[0][i] = i for i in range(len(a)+1): for j in range(len(b)+1): aaa = dp[i...
a = list(input()) b = list(input()) if len(a) == 0 or len(b) == 0: print(max(len(a),len(b))) else: dp = [[None for i in range(len(b)+1)] for j in range(len(a)+1)] for i in range(len(a)+1): dp[i][0] = i for i in range(len(b)+1): dp[0][i] = i for i in range(1,len(a)+1): for j in range(1,len(b)+1): aaa = ...
[["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 21]]
5
238
4
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline def leven(s1, s2): n1 = len(s1) n2 = len(s2) dp = [[0]*(n1+1) for _ in range(n2+1)] for i in range(1, n1+1): dp[0][i] = i for i in range(1, n2+1): dp[i][0] = i for j in range(1, ...
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline def leven(s1, s2): n1 = len(s1) n2 = len(s2) dp = [[0]*(n1+1) for _ in range(n2+1)] for i in range(1, n1+1): dp[0][i] = i for i in range(1, n2+1): dp[i][0] = i for j in range(1, ...
[["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 57, 15, 666, 0, 206, 206, 657, 31, 22], ["+", 0, 57, 15, 666, 0, 206, 206, 657, 31, 22]]
5
255
8
s1 = input() s2 = input() dp = [[i+j for j in range(len(s2)+1)] for i in range(len(s1)+1)] for i in range(len(s1)): for j in range(len(s2)): dp[i+1][j+1] = min(dp[i][j+1] + 1, dp[i+1][j-1] + 1, dp[i][j] + 1 * (s1[i] != s2[j])) print(dp[len(s1)][len(s2)])
s1 = input() s2 = input() dp = [[i+j for j in range(len(s2)+1)] for i in range(len(s1)+1)] for i in range(len(s1)): for j in range(len(s2)): dp[i+1][j+1] = min(dp[i][j+1] + 1, dp[i+1][j] + 1, dp[i][j] + 1 * (s1[i] != s2[j])) print(dp[len(s1)][len(s2)])
[["-", 3, 4, 0, 657, 31, 206, 206, 657, 17, 33], ["-", 3, 4, 0, 657, 31, 206, 206, 657, 12, 612]]
5
143
2
#include <bits/stdc++.h> using namespace std; using Int = long long; template <Int MOD = 1000000007> struct Mod { Int prev = 0; vector<Int> fact, inv, finv; Mod() {} Mod(Int n) { init(n); } Int pow(Int x, Int n) { Int res = 1; while (n) { if (n & 1) (res *= x) %= MOD; (x *= x) %=...
#include <bits/stdc++.h> using namespace std; using Int = long long; template <Int MOD = 1000000007> struct Mod { Int prev = 0; vector<Int> fact, inv, finv; Mod() {} Mod(Int n) { init(n); } Int pow(Int x, Int n) { Int res = 1; while (n) { if (n & 1) (res *= x) %= MOD; (x *= x) %=...
[["-", 8, 9, 0, 37, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 37, 0, 2, 3, 4, 0, 22]]
1
728
2
#include <bits/stdc++.h> using namespace std; const int N = 15, M = 1000, INF = 0x3f3f3f3f; int n, m; int du[N]; int dis[N][N]; int dp[1 << 16]; vector<int> v; inline int nextInt(void) { int res; scanf("%d", &res); return res; } inline void addEdge(int x, int y, int w) { dis[x][y] = dis[y][x] = min(dis[x][y]...
#include <bits/stdc++.h> using namespace std; const int N = 15, M = 1000, INF = 0x3f3f3f3f; int n, m; int du[N]; int dis[N][N]; int dp[1 << 16]; vector<int> v; inline int nextInt(void) { int res; scanf("%d", &res); return res; } inline void addEdge(int x, int y, int w) { dis[x][y] = dis[y][x] = min(dis[x][y]...
[["-", 8, 9, 0, 1, 0, 11, 12, 91, 17, 111], ["+", 8, 9, 0, 1, 0, 11, 12, 91, 17, 92], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22]]
1
624
5
#include <algorithm> #include <cstdio> using namespace std; int N, M, a, b, c, s, bit, d[19][19], dp[32777]; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { d[i][j] = (i == j ? 0 : 1 << 29); } } for (int i = 0; i < M; i++) { scanf("%d%d%d", &a, &...
#include <algorithm> #include <cstdio> using namespace std; int N, M, a, b, c, s, bit, d[19][19], dp[32777]; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { d[i][j] = (i == j ? 0 : 1 << 29); } } for (int i = 0; i < M; i++) { scanf("%d%d%d", &a, &...
[["-", 0, 7, 10, 43, 49, 50, 51, 23, 0, 24], ["-", 10, 43, 49, 50, 51, 23, 0, 16, 17, 152], ["-", 10, 43, 49, 50, 51, 23, 0, 16, 12, 13], ["-", 0, 7, 10, 43, 49, 50, 51, 23, 0, 25], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
438
6
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; const double EPS = 1.0e-9; const double INF = 1.0e20; int dsign(double d) { if (fabs(d) < EPS) { return 0; } else { return d < 0 ? -1 : 1; } } struct Point { int x, y; Point(int x =...
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; const double EPS = 1.0e-9; const double INF = 1.0e20; int dsign(double d) { if (fabs(d) < EPS) { return 0; } else { return d < 0 ? -1 : 1; } } struct Point { int x, y; Point(int x =...
[["-", 3, 4, 0, 16, 31, 2, 3, 4, 0, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 22]]
1
568
2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); String[] str = s.nextLine().split(" "); int H = Integer.parseInt(str[0]); int W = Integer.parseInt(str[1]); int[][] input = new int[W][H]; for (int i = 0; i < H; i++) { ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); String[] str = s.nextLine().split(" "); int H = Integer.parseInt(str[0]); int W = Integer.parseInt(str[1]); int[][] input = new int[W][H]; for (int i = 0; i < H; i++) { ...
[["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
3
508
4
import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int h = scan.nextInt(); int w = scan.nextInt(); scan.nextLine(); int[][] arr = new int[h][w]; for (int i = 0; i < h; i++) { String[] line = scan.nextLine().split(" "); ...
import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int h = scan.nextInt(); int w = scan.nextInt(); scan.nextLine(); int[][] arr = new int[h][w]; for (int i = 0; i < h; i++) { String[] line = scan.nextLine().split(" "); ...
[["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 48], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 12, 22]]
3
373
2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { int h, w; int[][] board; public static void main(String args[]) { new Main().run(); } void run() { FastReader sc = new FastReader(); h = sc.nextInt(); ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { int h, w; int[][] board; public static void main(String args[]) { new Main().run(); } void run() { FastReader sc = new FastReader(); h = sc.nextInt(); ...
[["-", 0, 11, 12, 510, 15, 16, 31, 504, 71, 499], ["+", 0, 11, 12, 510, 15, 16, 31, 504, 71, 22], ["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
3
651
4
#include <bits/stdc++.h> const long long INF = LLONG_MAX / 2; const long long MOD = 1000000007; const long double PI = 3.1415926; #define FOR(i, r, n) for (int i = (ll)(r); i < (ll)(n); i++) #define REP(i, n) FOR(i, (0), n) #define ll long long int using namespace std; ll ans = 0, sum = 0, n, k, counter = 0, w, h; stri...
#include <bits/stdc++.h> const long long INF = LLONG_MAX / 2; const long long MOD = 1000000007; const long double PI = 3.1415926; #define FOR(i, r, n) for (int i = (ll)(r); i < (ll)(n); i++) #define REP(i, n) FOR(i, (0), n) #define ll long long int using namespace std; ll ans = 0, sum = 0, n, k, counter = 0, w, h; stri...
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
314
3
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <iostream> #include <vector> using namespace std; class Disjointset { public: vector<int> p, ra; Disjointset(){}; Disjointset(int i) { p.resize(i, 0); ra.resize(i, 0); for (int j = 0; j < i; j++) setp(j); } void setp(int i) {...
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <iostream> #include <vector> using namespace std; class Disjointset { public: vector<int> p, ra; Disjointset(){}; Disjointset(int i) { p.resize(i, 0); ra.resize(i, 0); for (int j = 0; j < i; j++) setp(j); } void setp(int i) {...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
1
333
2
#include <iostream> using namespace std; int P[10010]; int n, q; int comp[100000 + 10]; int x[100000 + 10]; int y[100000 + 10]; void init(int N) { for (int i = 1; i <= N; ++i) { P[i] = i; } } int root(int a) { if (P[a] == a) { return a; } return (P[a] = root(P[a])); } bool is_same_set(int a, int b) ...
#include <iostream> using namespace std; int P[10010]; int n, q; int comp[100000 + 10]; int x[100000 + 10]; int y[100000 + 10]; void init(int N) { for (int i = 1; i <= N; ++i) { P[i] = i; } } int root(int a) { if (P[a] == a) { return a; } return (P[a] = root(P[a])); } bool is_same_set(int a, int b) ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
1
276
4
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxx = 10010; int pre[maxx]; int find(int x) { if (pre[x] != x) x = find(pre[x]); return x; } int main() { for (int i = 0; i < maxx; i++) pre[i] = i; int n, m; cin >> n >> m; int com, x, y; while (m--) { ...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxx = 10010; int pre[maxx]; int find(int x) { if (pre[x] != x) x = find(pre[x]); return x; } int main() { for (int i = 0; i < maxx; i++) pre[i] = i; int n, m; cin >> n >> m; int com, x, y; while (m--) { ...
[["-", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25], ["-", 0, 57, 15, 339, 51, 16, 12, 69, 28...
1
164
26
#include <iostream> using namespace std; bool same(int s1, int s2); void unite(int s1, int s2, int size, int *s); int main() { int n, q; cin >> n >> q; int set[n]; for (int i = 0; i < n; i++) set[i] = i; int com, x, y; for (int i = 0; i < q; i++) { cin >> com >> x >> y; switch (com) { c...
#include <iostream> using namespace std; bool same(int s1, int s2); void unite(int s1, int s2, int size, int *s); int main() { int n, q; cin >> n >> q; int set[n]; for (int i = 0; i < n; i++) set[i] = i; int com, x, y; for (int i = 0; i < q; i++) { cin >> com >> x >> y; switch (com) { c...
[["-", 75, 76, 0, 9, 0, 1, 0, 11, 12, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 22]]
1
293
2
#include <bits/stdc++.h> using namespace std; using Int = long long; template <Int MOD = 1000000007> struct Mod { Int prev = 0; vector<Int> fact, inv, finv; Mod() {} Mod(Int n) { init(n); } Int pow(Int x, Int n) { Int res = 1; while (n) { if (n & 1) (res *= x) %= MOD; (x *= x) %=...
#include <bits/stdc++.h> using namespace std; using Int = long long; template <Int MOD = 1000000007> struct Mod { Int prev = 0; vector<Int> fact, inv, finv; Mod() {} Mod(Int n) { init(n); } Int pow(Int x, Int n) { Int res = 1; while (n) { if (n & 1) (res *= x) %= MOD; (x *= x) %=...
[["-", 31, 16, 12, 23, 0, 41, 15, 16, 17, 19], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 17, 20]]
1
1,025
2
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; i++) #define rep(i, n) REP(i, ...
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; i++) #define rep(i, n) REP(i, ...
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 14, 8, 9, 0, 1, 0, 35]]
1
373
4
#include <stdio.h> #define N 10010 int n; int father[N]; int findfather(int x) { return x == father[x] ? x : findfather(father[x]); } void init() { for (int i = 0; i < n; i++) father[i] = i; } int main() { int m; scanf("%d %d", &n, &m); init(); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d ...
#include <stdio.h> #define N 10010 int n; int father[N]; int findfather(int x) { return x == father[x] ? x : findfather(father[x]); } void init() { for (int i = 0; i < n; i++) father[i] = i; } int main() { int m; scanf("%d %d", &n, &m); init(); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d ...
[["+", 64, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
182
3
#include <bits/stdc++.h> using namespace std; const int N = 10010; int fa[N]; int findfa(int x) { if (x == fa[x]) return x; return fa[x] = findfa(fa[x]); } int main() { int n, q; scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) fa[i] = i; for (int time = 0; time < q; time++) { int a, b, c; ...
#include <bits/stdc++.h> using namespace std; const int N = 10010; int fa[N]; int findfa(int x) { if (x == fa[x]) return x; return fa[x] = findfa(fa[x]); } int main() { int n, q; scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) fa[i] = i; for (int time = 0; time < q; time++) { int a, b, c; ...
[["-", 0, 41, 15, 16, 12, 2, 3, 4, 0, 22], ["+", 0, 41, 15, 16, 12, 2, 3, 4, 0, 22]]
1
185
2
#include <bits/stdc++.h> #define ll long long using namespace std; struct union_find_tree { vector<ll> par; union_find_tree(ll n) { par.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; } } ll find(ll a) { if (par[a] == a) return a; return par[a] = find(par[a]); } void...
#include <bits/stdc++.h> #define ll long long using namespace std; struct union_find_tree { vector<ll> par; union_find_tree(ll n) { par.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; } } ll find(ll a) { if (par[a] == a) return a; return par[a] = find(par[a]); } void...
[["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
236
3
#include <iostream> #include <vector> using namespace std; int n, q, com, x, y; int group[10000]; vector<int> f[10000]; int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) group[i] = i, f[i].push_back(i); for (int i = 0; i < q; i++) { scanf("%d%d%d", &com, &x, &y); if (com == 0) { if...
#include <iostream> #include <vector> using namespace std; int n, q, com, x, y; int group[10000]; vector<int> f[10000]; int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) group[i] = i, f[i].push_back(i); for (int i = 0; i < q; i++) { scanf("%d%d%d", &com, &x, &y); if (com == 0) { if...
[["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["-", 3, 4, 0, 69, 28, 69, 341, 342, 0, 22], ["+", 3, 4, 0, 69, 28, 69, 341, 342, 0, 22]]
1
339
4
#include <iostream> using namespace std; int P[10010]; // Include points from 0 ~ 10000 void init(int N) { // Initially all the points are individualized for (int i = 0; i <= N; ++i) P[i] = i; } int root(int a) { // find the root of a if (P[a] == a) return a; // a is the root return...
#include <iostream> using namespace std; int P[10010]; // Include points from 0 ~ 10000 void init(int N) { // Initially all the points are individualized for (int i = 0; i <= N; ++i) P[i] = i; } int root(int a) { // find the root of a if (P[a] == a) return a; // a is the root return...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22]]
1
217
4
#include <iostream> #include <vector> using namespace std; #define MAX_N 114514 vector<int> X[MAX_N]; int Group[MAX_N], N, Q, A, B, C; int main() { cin >> N >> Q; for (int i = 0; i < MAX_N; i++) { X[i].push_back(i); Group[i] = i; } for (int i = 0; i < Q; i++) { cin >> A >> B >> C; int D = Group[...
#include <iostream> #include <vector> using namespace std; #define MAX_N 114514 vector<int> X[MAX_N]; int Group[MAX_N], N, Q, A, B, C; int main() { cin >> N >> Q; for (int i = 0; i < MAX_N; i++) { X[i].push_back(i); Group[i] = i; } for (int i = 0; i < Q; i++) { cin >> A >> B >> C; int D = Group[...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
333
4
#include <iostream> using namespace std; #include <stdio.h> int *S; int root(int a) { if (S[a] == a) return a; S[a] = root(S[a]); return S[a]; } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { int a = root(x), b = root(y); S[x] = y; } int main() { int i, n, q; sc...
#include <iostream> using namespace std; #include <stdio.h> int *S; int root(int a) { if (S[a] == a) return a; S[a] = root(S[a]); return S[a]; } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { int a = root(x), b = root(y); S[a] = b; } int main() { int i, n, q; sc...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22]]
1
247
4
#include <bits/stdc++.h> using namespace std; class UnionFind { private: vector<int> v; public: UnionFind(int n) { for (int i = 0; i < n; i++) v.emplace_back(-1); } int root(int x) { return v[x] < 0 ? x : v[x] = root(v[x]); } void unite(int x, int y) { if (root(x) == root(y)) { return; ...
#include <bits/stdc++.h> using namespace std; class UnionFind { private: vector<int> v; public: UnionFind(int n) { for (int i = 0; i < n; i++) v.emplace_back(-1); } int root(int x) { return v[x] < 0 ? x : v[x] = root(v[x]); } void unite(int x, int y) { if (root(x) == root(y)) { return; ...
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111]]
1
226
1
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionS...
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionS...
[["-", 0, 57, 15, 339, 51, 16, 12, 5, 0, 6], ["+", 0, 57, 15, 339, 51, 16, 12, 5, 0, 6]]
1
329
2
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionS...
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) {} bool unionS...
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111]]
1
308
1
#include <iostream> using namespace std; #include <vector> struct UF { int n; vector<int> parent, rank; UF(int n_ = 0) : n(n_), parent(n_), rank(n_, 0) { for (int i = 0; i < n_; i++) parent[i] = i; } int find(int a) { return parent[a] != a ? parent[a] = find(parent[a]) : a; } bool same(int a, int ...
#include <iostream> using namespace std; #include <vector> struct UF { int n; vector<int> parent, rank; UF(int n_ = 0) : n(n_), parent(n_), rank(n_, 0) { for (int i = 0; i < n_; i++) parent[i] = i; } int find(int a) { return parent[a] != a ? parent[a] = find(parent[a]) : a; } bool same(int a, int ...
[["-", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111]]
1
285
12
$stdin.read array = lines.split("\n") n = array[0].split(" ")[0].to_i q = array[0].split(" ")[1].to_i it = -1 id = Array.new(n){it+=1} sn = Array.new(id) def root(i, id) while i != id[i] do i = id[i] end i end # find, check if p and q has the same root def same?(p, q, id) root(p, id) == root(q, id) end...
lines = $stdin.read array = lines.split("\n") n = array[0].split(" ")[0].to_i q = array[0].split(" ")[1].to_i it = -1 id = Array.new(n){it+=1} sn = Array.new(id) def root(i, id) while i != id[i] do i = id[i] end i end # find, check if p and q has the same root def same?(p, q, id) root(p, id) == root(q,...
[["+", 36, 36, 36, 36, 0, 493, 0, 662, 31, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32]]
4
250
2
h, w = map(int, input().split()) max_rect, prev = 0, [0] * (w + 1) for i in range(h): current = [p + 1 if f else 0 for f, p in zip(map(lambda x: int(x) ^ 1, input().split()), prev)] + [0] stack = [(0, 0)] for j in range(w + 1): c_j = current[j] if stack[-1][0] < c_j: stack.append...
h, w = map(int, input().split()) max_rect, prev = 0, [0] * (w + 1) for i in range(h): current = [p + 1 if f else 0 for f, p in zip(map(lambda x: int(x) ^ 1, input().split()), prev)] + [0] stack = [(0, 0)] for j in range(w + 1): c_j = current[j] if stack[-1][0] < c_j: stack.append...
[["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 660, 0, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 660, 0, 22]]
5
199
5
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 output: 6 """ import sys class Rectangle(object): __slots__ = ('pos', 'height') def __init__(self, pos=float('inf'), height=-1): """ init a Rectangle """ self.pos = pos ...
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 output: 6 """ import sys class Rectangle(object): __slots__ = ('pos', 'height') def __init__(self, pos=float('inf'), height=-1): """ init a Rectangle """ self.pos = pos ...
[["-", 0, 662, 12, 657, 12, 23, 0, 657, 31, 22], ["+", 0, 662, 12, 657, 12, 23, 0, 657, 31, 22]]
5
396
2
// AOJ DPL_3_C Largest Rectangle in a Histogram // 2018.5.12 bal4u #include <stdio.h> #include <stdlib.h> #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } typedef struct { int lp...
// AOJ DPL_3_C Largest Rectangle in a Histogram // 2018.5.12 bal4u #include <stdio.h> #include <stdlib.h> #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } typedef struct { int lp...
[["+", 31, 11, 31, 118, 28, 69, 71, 27, 17, 29], ["-", 12, 11, 31, 118, 28, 69, 71, 27, 17, 29]]
0
372
2
#include <bits/stdc++.h> #define int long long int #define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define RFORE(i, a, b) for (int i = (b); i >= (a); --i) #de...
#include <bits/stdc++.h> #define int long long int #define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define RFORE(i, a, b) for (int i = (b); i >= (a); --i) #de...
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 17, 72]]
1
968
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 << 17; // = 131072 const ll INF = (1e9) + 10; /*dat???????????????N?????????*/ class RMQ { public: ll n, dat[2 * N - 1]; //????????? RMQ() { n = N; for (int i = 0; i < n; i++) dat[i] = INF; } // k????????????...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 << 17; // = 131072 const ll INF = (1e9) + 10; /*dat???????????????N?????????*/ class RMQ { public: ll n, dat[2 * N - 1]; //????????? RMQ() { n = N; for (int i = 0; i < 2 * n - 1; i++) dat[i] = INF; } // k????...
[["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 13], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
1
578
6
N = int(input()) *H, = map(int, input().split()) st = [(0, -1)] ans = 0 for i in range(N): h = H[i] base = i while h <= st[-1][0]: h0, j = st.pop() ans = max(ans, (i-j)*h0) base = j st.append((h, base)) while st: h0, j = st.pop() ans = max(ans, (N-j)*h0) print(ans)
N = int(input()) *H, = map(int, input().split()) st = [(0, -1)] ans = 0 for i in range(N): h = H[i] base = i while st and h <= st[-1][0]: h0, j = st.pop() ans = max(ans, (i-j)*h0) base = j st.append((h, base)) while st: h0, j = st.pop() ans = max(ans, (N-j)*h0) print(ans)
[["+", 0, 7, 8, 196, 0, 52, 15, 679, 31, 22], ["+", 0, 7, 8, 196, 0, 52, 15, 679, 17, 355]]
5
132
2
#include <iostream> #include <map> #include <vector> #define ll long long using namespace std; /* a[i] + b[j] + c[k] + d[l] = V ??? a[i] = V - b[j] - c[k] - d[l] ( O(N) + O(N^3) ?? ) ??? a[i] + b[j] = V - c[k] - d[l] ( O(N^2) + O(N^2) ???) */ int main() { cin.tie(0); ...
#include <iostream> #include <map> #include <vector> #define ll long long using namespace std; /* a[i] + b[j] + c[k] + d[l] = V ??? a[i] = V - b[j] - c[k] - d[l] ( O(N) + O(N^3) ?? ) ??? a[i] + b[j] = V - c[k] - d[l] ( O(N^2) + O(N^2) ???) */ int main() { cin.tie(0); ...
[["-", 341, 342, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 341, 342, 0, 16, 12, 69, 341, 342, 0, 22]]
1
266
2
#include <algorithm> #include <iostream> #include <vector> #pragma warning(disable : 4996) using namespace std; int n; long long x, a[1009], b[1009], c[1009], d[1009], e[1000009], f[1000009], g[1000009], cnt[1000009]; int main() { scanf("%d%lld", &n, &x); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); ...
#include <algorithm> #include <iostream> #include <vector> #pragma warning(disable : 4996) using namespace std; int n; long long x, a[1009], b[1009], c[1009], d[1009], e[1000009], f[1000009], g[1000009], cnt[1000009]; int main() { scanf("%d%lld", &n, &x); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); ...
[["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 48], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 22]]
1
433
2
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { int n; ll v; cin >> n >> v; vector<ll> a(n), b(n), c(n), d(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i...
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { int n; ll v; cin >> n >> v; vector<ll> a(n), b(n), c(n), d(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i...
[["-", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22]]
1
325
2
#include <bits/stdc++.h> #define F first #define S second #define mp make_pair // everything go according to my plan #define pb push_back #define sz(a) (int)(a.size()) #define vec vector // shimkenttin kyzdary, dzyn, dzyn, dzyn... #define y1 Y_U_NO_y1 #define left Y_U_NO_left #define right Y_U_NO_right using namespac...
#include <bits/stdc++.h> #define F first #define S second #define mp make_pair // everything go according to my plan #define pb push_back #define sz(a) (int)(a.size()) #define vec vector // shimkenttin kyzdary, dzyn, dzyn, dzyn... #define y1 Y_U_NO_y1 #define left Y_U_NO_left #define right Y_U_NO_right using namespac...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["-", 12, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 12, 23, 0, 16, 12, 69, 341, 342, 0, 22]]
1
525
6
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (...
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (...
[["-", 49, 50, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 22]]
1
389
2
#include <bits/stdc++.h> using namespace std; using lint = long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; template <class T> void assign(V<T> &v, int n, const T &a = T()) { v.assign(n, a); } template <class T, class... Args> void assign(V<T> &v, int n, const ...
#include <bits/stdc++.h> using namespace std; using lint = long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; template <class T> void assign(V<T> &v, int n, const T &a = T()) { v.assign(n, a); } template <class T, class... Args> void assign(V<T> &v, int n, const ...
[["-", 8, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 8, 57, 15, 339, 51, 16, 31, 118, 119, 120]]
1
583
2
#include <bits/stdc++.h> #define int long long #define N 41 using namespace std; typedef pair<int, int> P; int Max(int &a, int b) { return a = max(a, b); } P calc(int bit, int a, int v[], int w[]) { int rv = 0, rw = 0; for (int i = 0; i < a; i++) if (bit >> i & 1) rv += v[i], rw += w[i]; return P(rw, ...
#include <bits/stdc++.h> #define int long long #define N 41 using namespace std; typedef pair<int, int> P; int Max(int &a, int b) { return a = max(a, b); } P calc(int bit, int a, int v[], int w[]) { int rv = 0, rw = 0; for (int i = 0; i < a; i++) if (bit >> i & 1) rv += v[i], rw += w[i]; return P(rw, ...
[["+", 0, 14, 8, 9, 0, 338, 49, 352, 0, 67]]
1
375
1
#include <algorithm> #include <cstdio> #include <utility> using namespace std; typedef long long ll; static const int MAX_N = 40; static const ll INF = 1 << 30; int n; ll w[MAX_N], v[MAX_N]; ll W; pair<ll, ll> ps[1 << (MAX_N / 2)]; void solve() { int n2 = n / 2; for (int i = 0; i < 1 << n2; i++) { ll sw = 0,...
#include <algorithm> #include <cstdio> #include <utility> using namespace std; typedef long long ll; static const int MAX_N = 40; static const ll INF = 1 << 30; int n; ll w[MAX_N], v[MAX_N]; ll W; pair<ll, ll> ps[1 << (MAX_N / 2)]; void solve() { int n2 = n / 2; for (int i = 0; i < 1 << n2; i++) { ll sw = 0,...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
423
4
/* * Contents : AOJ DPL 1 H * Author : Kitaura Hiromi * LastUpdate : 20180625 * Since : 20180625 */ #include <algorithm> #include <iostream> #include <map> #include <stdio.h> typedef long long ll; using namespace std; ll v[40], w[40]; ll INF = (1 << 20); pair<ll, ll> ps[1 << 20]; // sw, svを保持 ll N, W; i...
/* * Contents : AOJ DPL 1 H * Author : Kitaura Hiromi * LastUpdate : 20180625 * Since : 20180625 */ #include <algorithm> #include <iostream> #include <map> #include <stdio.h> typedef long long ll; using namespace std; ll v[40], w[40]; ll INF = (1 << 20); pair<ll, ll> ps[1 << 20]; // sw, svを保持 ll N, W; i...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 27, 28, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 27, 17, 29], ["-", 0, 11, 12, 69, 341, 342, 0, 27, 28, 22], ["-", 0, 11, 12, 69, 341, 342, 0, 27, 17, 29], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
402
6
#include <bits/stdc++.h> using namespace std; #define int long long #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() constexpr int INF = 1000000000000000000LL; template <typename A, typename B> void cmax(A &a, const B &b) { if (a < b) a = ...
#include <bits/stdc++.h> using namespace std; #define int long long #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() constexpr int INF = 1000000000000000000LL; template <typename A, typename B> void cmax(A &a, const B &b) { if (a < b) a = ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
497
2
import java.util.*; import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int N, M; int INF = Integer.MAX_VALUE / 2; int[][] graph; Map<Integer, Map<Integer, Integer>> dp = new HashMap<>(); void run() { N = sc.nextInt(); M = sc.nextInt(); g...
import java.util.*; import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int N, M; int INF = Integer.MAX_VALUE / 2; int[][] graph; Map<Integer, Map<Integer, Integer>> dp = new HashMap<>(); void run() { N = sc.nextInt(); M = sc.nextInt(); g...
[["-", 0, 503, 49, 200, 51, 16, 31, 504, 71, 499], ["+", 0, 503, 49, 200, 51, 16, 31, 504, 71, 22], ["-", 3, 4, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 12, 22]]
3
419
4
import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int N, M; int INF = Integer.MAX_VALUE / 2; int[][] graph, memo; void run() { N = sc.nextInt(); // edge number M = sc.nextInt(); // vertex number graph = new int[N][N]; memo = new int[N...
import java.util.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); int N, M; int INF = Integer.MAX_VALUE / 2; int[][] graph, memo; void run() { N = sc.nextInt(); // edge number M = sc.nextInt(); // vertex number graph = new int[N][N]; memo = new int[N...
[["-", 3, 4, 0, 16, 31, 504, 516, 504, 71, 22], ["+", 3, 4, 0, 16, 31, 504, 516, 504, 71, 22], ["-", 12, 492, 3, 4, 0, 16, 31, 504, 71, 22], ["+", 12, 492, 3, 4, 0, 16, 31, 504, 71, 22]]
3
374
4
#include <iostream> #include <vector> class Route { public: Route(const int &n = 0) : state(n){}; bool filled() const { return state == ((1 << size) - 1); } Route remove(const int &n) const { return Route(state & (-1 - (1 << n))); } Route add(const int &n) const { return Route(state | (1 << n)); } bool inclu...
#include <iostream> #include <vector> class Route { public: Route(const int &n = 0) : state(n){}; bool filled() const { return state == ((1 << size) - 1); } Route remove(const int &n) const { return Route(state & (-1 - (1 << n))); } Route add(const int &n) const { return Route(state | (1 << n)); } bool inclu...
[["-", 75, 76, 0, 9, 0, 43, 49, 50, 51, 13], ["+", 75, 76, 0, 9, 0, 43, 49, 50, 51, 13]]
1
822
2
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int inf = 987654321; int n, m; vector<vector<int>> G; vector<vector<int>> dp; int rec(int visited, int now) { if (dp[visited][now] != -1) return dp[visited][now]; if (visited == (1 << n) - 1 && now == 0) return dp[visite...
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int inf = 987654321; int n, m; vector<vector<int>> G; vector<vector<int>> dp; int rec(int visited, int now) { if (dp[visited][now] != -1) return dp[visited][now]; if (visited == (1 << n) - 1 && now == 0) return dp[visite...
[["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
1
291
2
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 18 #define INF 1000000000 int N, M, a, b, c, x[MAX_N][MAX_N]; int dp[MAX_N][1 << MAX_N]; int main() { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { x[i][j] = INF; } for (int j = 0; j < (1 << MAX_N); j...
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 18 #define INF 1000000000 int N, M, a, b, c, x[MAX_N][MAX_N]; int dp[MAX_N][1 << MAX_N]; int main() { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { x[i][j] = INF; } for (int j = 0; j < (1 << MAX_N); j...
[["-", 0, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["+", 0, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 3, 4, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 3, 4, 0, 16, 12, 69, 341, 342, 0, 13]]
1
381
4
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define gsort(st, en) sort((st), (en), greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " ...
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define gsort(st, en) sort((st), (en), greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " ...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
541
2
#include <stdio.h> #define MAX 987654321 int V, E, A[15][15], MEMO[15][32768], VISIT[15][32768]; void input(void); void init_A(void); void init_MEMO(void); int DP(int origin, int dest, int VIA); int TSP(void); int main(void) { // freopen("in.txt", "r", stdin); input(); printf("%d\n", TSP()); return 0; } int TSP...
#include <stdio.h> #define MAX 987654321 int V, E, A[15][15], MEMO[15][32768], VISIT[15][32768]; void input(void); void init_A(void); void init_MEMO(void); int DP(int origin, int dest, int VIA); int TSP(void); int main(void) { // freopen("in.txt", "r", stdin); input(); printf("%d\n", TSP()); return 0; } int TSP...
[["-", 64, 37, 0, 69, 28, 69, 341, 342, 0, 13], ["+", 64, 37, 0, 69, 28, 69, 341, 342, 0, 22]]
1
551
2
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES //#include "MyMath.h" //#include "MyDisjointset.h" #include <algorithm> #include <functional> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef pair<int, int> P; typedef l...
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES //#include "MyMath.h" //#include "MyDisjointset.h" #include <algorithm> #include <functional> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef pair<int, int> P; typedef l...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
320
2
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES //#include "MyMath.h" //#include "MyDisjointset.h" #include <algorithm> #include <functional> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef pair<int, int> P; typedef l...
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES //#include "MyMath.h" //#include "MyDisjointset.h" #include <algorithm> #include <functional> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef pair<int, int> P; typedef l...
[["-", 3, 4, 0, 16, 31, 69, 28, 69, 28, 22], ["+", 3, 4, 0, 16, 31, 69, 28, 69, 28, 22], ["-", 3, 4, 0, 16, 12, 69, 28, 69, 28, 22], ["+", 3, 4, 0, 16, 12, 69, 28, 69, 28, 22]]
1
304
4
#include <bits/stdc++.h> using namespace std; struct TSP { int n, d[16][16], dp[(1 << 16)][16]; TSP(int sz) : n(sz) { for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) d[i][j] = 1e8; } void add(int a, int b, int c) { d[a][b] = c; // d[b][a] = c; } int solve() { for (int...
#include <bits/stdc++.h> using namespace std; struct TSP { int n, d[16][16], dp[(1 << 16)][16]; TSP(int sz) : n(sz) { for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) d[i][j] = 1e8; } void add(int a, int b, int c) { d[a][b] = c; // d[b][a] = c; } int solve() { for (int...
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
392
2
#include <bits/stdc++.h> using namespace std; #define inf (pow(10, 9)) typedef pair<int, int> pii; int V = 0; int E = 0; vector<pii> graph[20]; // from,{to,cost} int dp[1 << 15][15] = {0}; int DP(int bit, int v) { if (dp[bit][v] != inf) return dp[bit][v]; if (bit == (1 << V) - 1 && v == 0) return dp[bit...
#include <bits/stdc++.h> using namespace std; #define inf (pow(10, 9)) typedef pair<int, int> pii; int V = 0; int E = 0; vector<pii> graph[20]; // from,{to,cost} int dp[1 << 15][15] = {0}; int DP(int bit, int v) { if (dp[bit][v] != inf) return dp[bit][v]; if (bit == (1 << V) - 1 && v == 0) return dp[bit...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 33], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25]]
1
379
6
// 巡回セールスマン問題 // 蟻本p173と同じ。 // 訪問済状態をビットで表すとbitDPで解ける #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include ...
// 巡回セールスマン問題 // 蟻本p173と同じ。 // 訪問済状態をビットで表すとbitDPで解ける #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include ...
[["-", 15, 339, 51, 91, 28, 23, 0, 16, 17, 139], ["+", 15, 339, 51, 91, 28, 23, 0, 16, 17, 67], ["+", 51, 91, 28, 23, 0, 16, 12, 23, 0, 24], ["+", 51, 91, 28, 23, 0, 16, 12, 23, 0, 25]]
1
420
4
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; int main() { long long int V, E; cin >> V >> E;...
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; int main() { long long int V, E; cin >> V >> E;...
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
374
2
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h + 2, vector<int>(w + 2, 1)); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; } } vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0)); int ans = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h + 2, vector<int>(w + 2, 1)); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; } } vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0)); int ans = 0; ...
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
249
3
#include <algorithm> #include <iostream> #include <vector> using namespace std; static const int MAX_N = 1400; int dp[MAX_N + 1][MAX_N + 1]; int main(void) { int H, W; cin >> H >> W; for (int i = 0; i < H; i++) { dp[i][0] = 0; } for (int i = 0; i < W; i++) { dp[0][i] = 0; } int tmp; for (int...
#include <algorithm> #include <iostream> #include <vector> using namespace std; static const int MAX_N = 1400; int dp[MAX_N + 1][MAX_N + 1]; int main(void) { int H, W; cin >> H >> W; for (int i = 0; i < H; i++) { dp[i][0] = 0; } for (int i = 0; i < W; i++) { dp[0][i] = 0; } int tmp; for (int...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
1
276
2
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> T(h + 1, vector<int>(w + 1, 0)); vector<vector<int>> A(h + 1, vector<int>(w + 1, 0)); for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> T[i][j]...
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> T(h + 1, vector<int>(w + 1, 0)); vector<vector<int>> A(h + 1, vector<int>(w + 1, 0)); for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> T[i][j]...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
250
2
#include <algorithm> #include <iostream> using namespace std; int main() { int W, H; cin >> W >> H; int dp[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> dp[i][j]; dp[i][j] ^= 1; } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) ...
#include <algorithm> #include <iostream> using namespace std; int main() { int W, H; cin >> H >> W; int dp[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> dp[i][j]; dp[i][j] ^= 1; } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) ...
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
224
4
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define all(r) begin(r), end(r) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " << x << endl #define fcout(n) cout << fixed << setprecision((...
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define all(r) begin(r), end(r) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " << x << endl #define fcout(n) cout << fixed << setprecision((...
[["-", 0, 43, 49, 50, 51, 4, 0, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 31, 22], ["-", 51, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 51, 4, 0, 2, 3, 4, 0, 16, 31, 22]]
1
817
4
#include <iostream> using namespace std; int main() { int dp[1401][1401] = {0}, min, max, a, w, h; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a; if (a == 0) dp[i][j] = -1; } } /*for(int i=0;i<=h;i++){///// for(int j=0;j<=w;j++){ c...
#include <iostream> using namespace std; int main() { int dp[1401][1401] = {0}, min, max, a, w, h; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a; if (a == 0) dp[i][j] = -1; } } /*for(int i=0;i<=h;i++){///// for(int j=0;j<=w;j++){ c...
[["-", 64, 9, 0, 1, 0, 11, 12, 27, 17, 29], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
260
3
#include <iostream> using namespace std; int main() { int dp[1401][1401] = {0}, min, max, a, w, h; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a; if (a == 0) dp[i][j] = -1; } } /*for(int i=0;i<=h;i++){///// for(int j=0;j<=w;j++){ c...
#include <iostream> using namespace std; int main() { int dp[1401][1401] = {0}, min, max, a, w, h; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a; if (a == 0) dp[i][j] = -1; } } max = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j ...
[["-", 64, 9, 0, 1, 0, 11, 12, 27, 17, 29], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
260
3
#include <iostream> #define HMAX 140 #define WMAX 140 using namespace std; int main() { int H, W, ms = 1; int dp[HMAX + 10][WMAX + 10] = {}; cin >> H >> W; for (int i = 1; i < H + 1; ++i) { for (int j = 1; j < W + 1; ++j) { cin >> dp[i][j]; if (dp[i][j] == 0) { dp[i][j] = 1; } else...
#include <iostream> #define HMAX 1400 #define WMAX 1400 using namespace std; int main() { int H, W, ms = 0; int dp[HMAX + 10][WMAX + 10] = {}; cin >> H >> W; for (int i = 1; i < H + 1; ++i) { for (int j = 1; j < W + 1; ++j) { cin >> dp[i][j]; if (dp[i][j] == 0) { dp[i][j] = 1; } el...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
261
6
#include <iostream> #include <vector> using namespace std; #define debug(x) cout << #x << "==" << x << endl; const int inf = 100000000; typedef long long ll; #define MAX_H 1400 #define MAX_W 1400 int field[MAX_H][MAX_W]; int main() { ios::sync_with_stdio(false); int H, W; cin >> H >> W; for (int i = 0; ...
#include <iostream> #include <vector> using namespace std; #define debug(x) cout << #x << "==" << x << endl; const int inf = 100000000; typedef long long ll; #define MAX_H 1400 #define MAX_W 1400 int field[MAX_H][MAX_W]; int main() { ios::sync_with_stdio(false); int H, W; cin >> H >> W; for (int i = 0; ...
[["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 104], ["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 48]]
1
347
6
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int H, W; scanf("%d %d", &H, &W); int A[H + 1][W + 1]; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { scanf("%d", &A[i][j]); } } int G[H + 1][W + 1]; for (int i = 0; i <= H; ++i) {...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int H, W; scanf("%d %d", &H, &W); int A[H + 1][W + 1]; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { scanf("%d", &A[i][j]); } } int G[H + 1][W + 1]; for (int i = 0; i <= H; ++i) {...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
1
298
2
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int H, W; scanf("%d %d", &H, &W); int A[H + 1][W + 1]; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { scanf("%d", &A[i][j]); } } int V[H + 1][W + 1]; for (int i = 0; i <= H; ++i) ...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int H, W; scanf("%d %d", &H, &W); int A[H + 1][W + 1]; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { scanf("%d", &A[i][j]); } } int V[H + 1][W + 1]; for (int i = 0; i <= H; ++i) ...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
298
2
#include <algorithm> #include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; int tile[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> tile[i][j]; } } int dp[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (til...
#include <algorithm> #include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; int tile[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> tile[i][j]; } } int dp[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (til...
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
1
351
2
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define rep(i, n) FOR(i, 0, n) #define DEBUG(x) cout << #x << ": " << x << endl #define vint vector<int> #define vdouble ve...
[["-", 0, 11, 12, 16, 31, 23, 0, 41, 0, 102], ["-", 0, 11, 12, 16, 31, 23, 0, 41, 75, 13], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 41, 64, 16, 12, 2, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 23, 0, 41, 0, 102], ["+", 0, 1, 0, 11, 12, 23, 0, 41, 75, 13]]
1
309
6
/// // File: dpl_3_a.cpp // Author: ymiyamoto // // Created on Wed Nov 8 01:32:41 2017 // #include <cstdint> #include <iostream> using namespace std; #define MAX_H 1400 #define MAX_W 1400 static uint32_t arr[MAX_H][MAX_W]; int32_t main() { uint32_t H, W; cin >> H >> W; for (uint32_t i = 0; i < H; i++) { ...
/// // File: dpl_3_a.cpp // Author: ymiyamoto // // Created on Wed Nov 8 01:32:41 2017 // #include <cstdint> #include <iostream> using namespace std; #define MAX_H 1400 #define MAX_W 1400 static uint32_t arr[MAX_H][MAX_W]; int32_t main() { uint32_t H, W; cin >> H >> W; for (uint32_t i = 0; i < H; i++) { ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
1
248
2
// 問題: H*Wのタイルが与えられる。タイルは綺麗か汚れているかのいずれか。 // 綺麗なタイルのみでできる最大の正方形の最大値を求める // 解法: http://prdc.hatenablog.com/entry/2017/09/11/105211 // dp[i][j]: 位置(i,j)から見て、左上に向かってできる最大の正方形の数 #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #inc...
// 問題: H*Wのタイルが与えられる。タイルは綺麗か汚れているかのいずれか。 // 綺麗なタイルのみでできる最大の正方形の最大値を求める // 解法: http://prdc.hatenablog.com/entry/2017/09/11/105211 // dp[i][j]: 位置(i,j)から見て、左上に向かってできる最大の正方形の数 #include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #inc...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 14, 8, 9, 0, 37, 0, 1...
1
385
10
#include <iostream> using namespace std; int m, D[1401][1401] = {m = 0}, h, w, f, i, j; main() { cin >> h >> w; for (i = 0; i < h; i++) for (j = 0; j < w;) { cin >> f; m = max(m, D[i + 1][j + 1] = (min(D[i][j], min(D[i + 1][j], D[i][j++])) + 1) * (!f)); } cout << m * m << ...
#include <iostream> using namespace std; int m, D[1401][1401] = {m = 0}, h, w, f, i, j; main() { cin >> h >> w; for (i = 0; i < h; i++) for (j = 0; j < w; j++) { cin >> f; m = max(m, D[i + 1][j + 1] = (min(D[i][j], min(D[i + 1][j], D[i][j + 1])) + 1) * (!f)); } cout << m *...
[["+", 8, 9, 0, 7, 8, 7, 26, 27, 28, 22], ["+", 8, 9, 0, 7, 8, 7, 26, 27, 17, 29], ["-", 3, 4, 0, 69, 341, 342, 0, 27, 17, 29], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 17, 72], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
143
5
h, w = STDIN.gets.split.map(&:to_i) c = h.times.map { STDIN.gets.split.map(&:to_i) } dp = (h+1).times.map { (w+1).times.map { 0 } } (1..h).each do |i| (1..w).each do |j| p i, j if c[i-1][j-1] == 0 dp[i][j] = [dp[i-1][j-1], dp[i-1][j], dp[i][j-1]].min + 1 else dp[i][j] = 0 end end ...
h, w = STDIN.gets.split.map(&:to_i) c = h.times.map { STDIN.gets.split.map(&:to_i) } dp = (h+1).times.map { (w+1).times.map { 0 } } (1..h).each do |i| (1..w).each do |j| if c[i-1][j-1] == 0 dp[i][j] = [dp[i-1][j-1], dp[i-1][j], dp[i][j-1]].min + 1 else dp[i][j] = 0 end end end puts ...
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 21]]
4
166
4
h, w = map(int, input().split()) floor = [[1] + list(map(int, input().split())) for i in range(h)] max_square, prev = 0, [0] * (w + 1) for i in range(h): current = [0] * (w + 1) for j in range(1, w + 1): if floor[i][j]: current[j] = 0 continue current[j] = min(prev[j - 1]...
h, w = map(int, input().split()) floor = [[1] + list(map(int, input().split())) for i in range(h)] max_square, prev = 0, [0] * (w + 1) for i in range(h): current = [0] * (w + 1) for j in range(1, w + 1): if floor[i][j]: current[j] = 0 continue current[j] = min(prev[j - 1]...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
156
2
# -*- coding: utf-8 -*- from itertools import product H, W = tuple(map(int, input().split())) C = [tuple(map(int, input().split())) for _ in range(H)] S = [[1]*W for _ in range(H)] for h, w in product(range(H), range(W)): if C[h][w] == 1: S[h][w] = 0 for h, w in product(range(H), range(W)): if S[h][w]...
# -*- coding: utf-8 -*- from itertools import product H, W = tuple(map(int, input().split())) C = [tuple(map(int, input().split())) for _ in range(H)] S = [[1]*W for _ in range(H)] for h, w in product(range(H), range(W)): if C[h][w] == 1: S[h][w] = 0 for h, w in product(range(1, H), range(1, W)): if S...
[["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 612], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 21]]
5
200
4
# -*- coding: utf-8 -*- ''' http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_A&lang=jp ???????¨??????? ?????§??£?????¢ ''' H, W = map(int, input().split()) C = list() maxWidth = 0 for h in range(H): C.append(list(map(int, input().split()))) dp = dict() for h in range(H+1): dp[(h, 0)] = 0 for w...
# -*- coding: utf-8 -*- ''' http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_A&lang=jp ???????¨??????? ?????§??£?????¢ ''' H, W = map(int, input().split()) C = list() maxWidth = 0 for h in range(H): C.append(list(map(int, input().split()))) dp = dict() for h in range(H+1): dp[(h, 0)] = 0 for w...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 578], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
219
2
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long, long> pll; const int INF = 1 << 29; const double EPS = 1e...
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long, long> pll; const int INF = 1 << 29; const double EPS = 1e...
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
512
2
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, a) REP(i, 0, a) #define REP(i, ...
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, a) REP(i, 0, a) #define REP(i, ...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
1
517
2
#include <algorithm> #include <cstdio> #include <iostream> #include <stack> using namespace std; struct elem { int pos, height; }; int getArea(int V[], int W) { int area = 0; stack<elem> S; for (int i = 0; i <= W; ++i) { elem e; e.pos = i; if (i == W) { e.height = 0; } else { e.he...
#include <algorithm> #include <cstdio> #include <iostream> #include <stack> using namespace std; struct elem { int pos, height; }; int getArea(int V[], int W) { int area = 0; stack<elem> S; for (int i = 0; i <= W; ++i) { elem e; e.pos = i; if (i == W) { e.height = 0; } else { e.he...
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 11, 12, 118, 119, 120], ["+", 0, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
444
6
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> constexpr int MOD = 1000000000 + 7; constexpr int INF = 20000...
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> constexpr int MOD = 1000000000 + 7; constexpr int INF = 20000...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 1, 0, 11, 12, 41, 15, 23, 0, 25], ["-", 0, 9, 0, 1, 0, 11, 12, 23, 0, 25]]
1
492
4
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; a[i][j] = !a[i][j]; } } for (int i = 1; i < h; i++) { for (int j = 0; j < w; j++)...
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; a[i][j] = !a[i][j]; } } for (int i = 1; i < h; i++) { for (int j = 0; j < w; j++)...
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22]]
1
418
2
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; typedef vector<int> VI; typed...
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; typedef vector<int> VI; typed...
[["-", 12, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
1
624
2
# encoding: "utf-8" class Unreachable(Exception): pass class SetManager: def __init__(self, n): self.data = list() for i in range(n): self.data.append((i, {i})) def ref(self, i): return self.data[i][1] def set(self, i, value): self.data[i] = (i, value) ...
# encoding: "utf-8" class Unreachable(Exception): pass class SetManager: def __init__(self, n): self.data = list() for i in range(n): self.data.append((i, {i})) def ref(self, i): return self.data[i][1] def set(self, i, value): self.data[i] = (i, value) ...
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 79], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 102]]
5
346
5
n, nq = map(int, input().split()) set_list = list(range(n)) def find(n): global set_list if set_list[n] == n: return n result = set_list[n] = find(set_list[n]) return result def same(x, y): set_list[find(y)] = find(x) def unite(x, y): return find(x) == find(y) for _ in range(nq): ...
n, nq = map(int, input().split()) set_list = list(range(n)) def find(n): global set_list if set_list[n] == n: return n result = set_list[n] = find(set_list[n]) return result def same(x, y): set_list[find(y)] = find(x) def unite(x, y): return find(x) == find(y) for _ in range(nq): ...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612]]
5
154
4
#include <bits/stdc++.h> #define MAX 100010 #define inf 1 << 29 #define linf (1e16) #define eps (1e-8) #define Eps (1e-12) #define mod 1000000007 #define pi acos(-1.0) #define phi (1.0 + sqrt(5.0)) / 2.0 #define f first #define s second #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #de...
#include <bits/stdc++.h> #define MAX 100010 #define inf 1 << 29 #define linf (1e16) #define eps (1e-8) #define Eps (1e-12) #define mod 1000000007 #define pi acos(-1.0) #define phi (1.0 + sqrt(5.0)) / 2.0 #define f first #define s second #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #de...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 118, 28, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 118, 17, 131], ["+", 0, 1, 0, 11, 12, 16, 12, 118, 119, 120]]
1
467
4
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n)...
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n)...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
1
507
4
#include <algorithm> #include <climits> #include <iostream> #include <string> #include <vector> const int MAX_N = 1 << 17; using namespace std; int n, bit[MAX_N + 1]; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { ...
#include <algorithm> #include <climits> #include <iostream> #include <string> #include <vector> const int MAX_N = 1 << 17; using namespace std; int n, bit[MAX_N + 1]; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { ...
[["+", 0, 14, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
173
9
#include <algorithm> #include <cstdio> #include <vector> using namespace std; template <class T> struct fenwick_tree { vector<T> x; fenwick_tree(int n) : x(n, 0) {} T sum(int i, int j) { if (i == 0) { T S = 0; for (; j >= 0; j = (j & (j + 1)) - 1) S += x[j]; return S; } else ...
#include <algorithm> #include <cstdio> #include <vector> using namespace std; template <class T> struct fenwick_tree { vector<T> x; fenwick_tree(int n) : x(n, 0) {} T sum(int i, int j) { if (i == 0) { T S = 0; for (; j >= 0; j = (j & (j + 1)) - 1) S += x[j]; return S; } else ...
[["+", 3, 4, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
244
6
# range_sum_query # # s=STDIN.gets.split n = s[0].to_i q = s[1].to_i ar = Array.new(100001,0) ar2 = Array.new(1001 ,0) 1.upto(q) { s=STDIN.gets.split com = s[0].to_i x = s[1].to_i y = s[2].to_i #printf(":%d %d %d\n",com,x,y) if(com==0) x1=x/100 diff = y - ar[x] ar[x]=y ar2[x1] += diff elsif (com==1) ...
# range_sum_query # # s=STDIN.gets.split n = s[0].to_i q = s[1].to_i ar = Array.new(100001,0) ar2 = Array.new(1001 ,0) 1.upto(q) { s=STDIN.gets.split com = s[0].to_i x = s[1].to_i y = s[2].to_i #printf(":%d %d %d\n",com,x,y) if(com==0) x1=x/100 diff = y - ar[x] ar[x] += y ar2[x1] += y elsif (com==1) ...
[["-", 8, 734, 0, 121, 64, 749, 0, 662, 0, 32], ["+", 8, 734, 0, 121, 64, 749, 0, 755, 17, 107], ["-", 8, 734, 0, 121, 64, 749, 0, 755, 12, 22], ["+", 8, 734, 0, 121, 64, 749, 0, 755, 12, 22]]
4
265
4
n, q = gets.split.map(&:to_i) a = [0] * (n+1) sq = ((n+1)**0.5).to_i sa = [0] * (sq+1) q.times do com, x, y = gets.split.map(&:to_i) if com == 0 a[x] += y sa[x/sq] += y else sum = 0 if x/sq+1 >= y/sq x.upto(y) do |ai| sum += a[ai] end else x.upto(x/sq*sq-1) do |ai| sum += a[ai] end (...
n, q = gets.split.map(&:to_i) a = [0] * (n+1) sq = ((n+1)**0.5).to_i sa = [0] * (n/sq+1) q.times do com, x, y = gets.split.map(&:to_i) #p [com,x,y,a] if com == 0 a[x] += y sa[x/sq] += y else sum = 0 if x/sq+1 >= y/sq x.upto(y) do |ai| sum += a[ai] end else x.upto((x/sq+1)*sq-1) do |ai| s...
[["+", 12, 738, 12, 739, 0, 738, 31, 738, 31, 22], ["+", 12, 738, 12, 739, 0, 738, 31, 738, 17, 85], ["+", 0, 121, 75, 95, 0, 652, 3, 4, 0, 24], ["+", 0, 738, 31, 738, 31, 739, 0, 738, 17, 72], ["+", 0, 738, 31, 738, 31, 739, 0, 738, 12, 612], ["+", 3, 4, 0, 738, 31, 738, 31, 739, 0, 25]]
4
195
6
def add(a, b, k, l, r, node) return 0 if r <= a || b <= l return node[k] if a <= l && r <= b m = (l+r)/2 vl = add(a, b, 2*k+1, l, m, node) vr = add(a, b, 2*k+2, m, r, node) return vl + vr end n, q = gets.split.map(&:to_i) m = 1 while m < n m *= 2 end node = Array.new(2*m-1){0} q.times{ com, x, y = ge...
def add(a, b, k, l, r, node) return 0 if r <= a || b <= l return node[k] if a <= l && r <= b m = (l+r)/2 vl = add(a, b, 2*k+1, l, m, node) vr = add(a, b, 2*k+2, m, r, node) return vl + vr end n, q = gets.split.map(&:to_i) m = 1 while m < n m *= 2 end node = Array.new(2*m-1){0} q.times{ com, x, y = ge...
[["-", 3, 4, 0, 652, 3, 4, 0, 738, 17, 72], ["-", 3, 4, 0, 652, 3, 4, 0, 738, 12, 612]]
4
211
2
class SegmentTree def initialize @N=2**17 @INF=2**32-1 @seg=Array.new(2*@N-1){@INF} end def update(i, x) i+=@N-1 #??°??????i??????????????????????????¨???????????????????????? @seg[i]=x while i.nonzero? i=(i-1)/2 #????????????????????????????????¨???????????? @seg[i]=[@seg[2...
class SegmentTree def initialize @N=2**17 @INF=2**31-1 @seg=Array.new(2*@N-1){@INF} end def update(i, x) i+=@N-1 #??°??????i??????????????????????????¨???????????????????????? @seg[i]=x while i.nonzero? i=(i-1)/2 #????????????????????????????????¨???????????? @seg[i]=[@seg[2...
[["-", 8, 736, 0, 662, 12, 738, 31, 738, 12, 612], ["+", 8, 736, 0, 662, 12, 738, 31, 738, 12, 612], ["+", 3, 4, 0, 652, 3, 4, 0, 738, 17, 72], ["+", 3, 4, 0, 652, 3, 4, 0, 738, 12, 612]]
4
262
4
class RMQ INFINITY = 2**31 - 1 def initialize(size) @index = 1 @index *= 2 while @index < size @array = Array.new(@index * 2 - 1, INFINITY) end def find(x, y, k = 0, l = 0, r = @index) if r <= x || y <= l INFINITY elsif x <= l && r <= y @array[k] else ml = find(x, y, k...
class RMQ INFINITY = 2**31 - 1 def initialize(size) @index = 1 @index *= 2 while @index < size @array = Array.new(@index * 2 - 1, INFINITY) end def find(x, y, k = 0, l = 0, r = @index) if r <= x || y <= l INFINITY elsif x <= l && r <= y @array[k] else ml = find(x, y, k...
[["+", 12, 652, 486, 742, 0, 738, 31, 739, 0, 24], ["+", 12, 652, 486, 742, 0, 738, 31, 739, 0, 25], ["+", 0, 662, 12, 652, 486, 742, 0, 738, 17, 72], ["+", 0, 662, 12, 652, 486, 742, 0, 738, 12, 612]]
4
253
4
#単体変更, 区間取得 class RMQ: #INF = int(1e18) INF = int((1<<31)-1) n = 0 n_ = 0 val = [] def __init__(self, n_): n = 1 while n < n_: n = n * 2 self.n = n self.n_ = n_ self.val = [self.INF] * (2 * n - 1) @staticmethod def merge(a, b): ...
#単体変更, 区間取得 class RMQ: #INF = int(1e18) INF = int((1<<31)-1) n = 0 n_ = 0 val = [] def __init__(self, n_): n = 1 while n < n_: n = n * 2 self.n = n self.n_ = n_ self.val = [self.INF] * (2 * n - 1) @staticmethod def merge(a, b): ...
[["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 24], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 12, 612], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25]]
5
375
4
import sys #stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip...
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip(...
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 319, 0, 131], ["+", 0, 656, 0, 1, 0, 662, 12, 319, 319, 22], ["+", 0, 656, 0, 1, 0, 652, 63, 319, 500, 22]]
5
718
5
import time N, Q = map(int, input().split()) SegTree = [0 for i in range(4*N)] def modify(i, left, right, value, pos=-1): global SegTree if left==right: if pos != -1: SegTree[i] = value else: SegTree[i] = 2147483647 return mid = int((left+right)/2) if p...
import time N, Q = map(int, input().split()) SegTree = [0 for i in range(4*N)] def modify(i, left, right, value, pos=-1): global SegTree if left==right: if pos != -1: SegTree[i] = value else: SegTree[i] = 2147483647 return mid = int((left+right)/2) if p...
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 612], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 612]]
5
362
2
import sys; def init(n_): length = 1; while(length < n_): length*=2 element=[0]*(2*length-1) for i in range(2*length-1): element[i] = initial return element def update(k,a,element): k+=n element[k]=a while(k > 0): k = (int)((k-1)/2) element[k] = min(elem...
import sys; def init(n_): length = 1; while(length < n_): length*=2 element=[0]*(2*length-1) for i in range(2*length-1): element[i] = initial return element,length def update(k,a,element): k+=n-1 element[k]=a while(k > 0): k = (int)((k-1)/2) element[k] =...
[["+", 0, 14, 8, 196, 0, 37, 0, 432, 0, 21], ["+", 0, 14, 8, 196, 0, 37, 0, 432, 0, 22], ["+", 8, 196, 0, 1, 0, 677, 12, 657, 17, 33], ["+", 8, 196, 0, 1, 0, 677, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 31, 684, 0, 21], ["+", 0, 656, 0, 1, 0, 662, 31, 684, 0, 22]]
5
340
6