# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
169834 | 2019-12-23T00:13:01 Z | arthur_nascimento | Rectangles (IOI19_rect) | C++14 | 5000 ms | 492000 KB |
#include "rect.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define debug #define ll long long #define maxn 2525 int lg[maxn]; struct rmq { int len; int arr[maxn]; short id[13][maxn]; inline int mx(int i,int j){ return arr[id[i][j]]; } void build(){ lg[1] = 0; for(int i=2;i<=len;i++) lg[i] = lg[i-1] + (i == (i&-i)); for(int i=0;i<len;i++){ // mx[0][i] = arr[i]; id[0][i] = i; } for(int i=1;i<13;i++) for(int j=0;j<len;j++){ int ot = min(len-1, j + ( 1 << (i-1))); int A = mx(i-1,j) , B = mx(i-1,ot); if(A > B){ //mx[i][j] = A; id[i][j] = id[i-1][j]; } else { //mx[i][j] = B; id[i][j] = id[i-1][ot]; } } } int pos(int x,int y){ int l = lg[y-x+1]; int A = mx(l,x), B = mx(l,y-(1<<l)+1); if(A > B) return id[l][x]; else return id[l][y-(1<<l)+1]; } int val(int x,int y){ int l = lg[y-x+1]; int A = mx(l,x), B = mx(l,y-(1<<l)+1); return max(A,B); } } RMQ[2][maxn]; int M[maxn][maxn]; int n,m; int line(int i,int yi,int yf){ int r = 1; for(int j=yi;j<=yf;j++) if(M[i][j] >= M[i][yi-1] || M[i][j] >= M[i][yf+1]) r = 0; return r; } int column(int j,int xi,int xf){ int r = 1; for(int i=xi;i<=xf;i++) if(M[i][j] >= M[xi-1][j] || M[i][j] >= M[xf+1][j]) r = 0; return r; } int check(int xi,int xf,int yi,int yf){ for(int i=xi;i<=xf;i++) if( RMQ[0][i].val(yi,yf) >= min( M[i][yi-1],M[i][yf+1])) return 0; //for(int j=yi;j<=yf;j++) // if( RMQ[1][j].val(xi,xf) >= min( M[xi-1][j],M[xf+1][j])) return 0; return 1; //return 1; int r = 1; assert(xi >= 1 && xf <= n-2 && yi >= 1 && yf <= m-2); //for(int i=xi;i<=xf;i++) // r *= line(i,yi,yf); for(int j=yi;j<=yf;j++) r *= column(j,xi,xf); if(r) debug("achou x:%d~%d y: %d~%d\n",xi,xf,yi,yf); return r; } ll go4(int xi,int xf,int yi,int yf,int ym){ if(xi > xf || yi > yf) return 0; if(yi > ym || yf < ym) return 0; debug("oi4\n"); ll ans = check(xi,xf,yi,yf); int mx = -1, id = -1; /*for(int i=yi;i<=yf;i++) if(M[xi][i] > mx){ mx = M[xi][i]; id = i; }*/ id = RMQ[0][xi].pos(yi,yf); ans += go4(xi,xf,yi,id-1,ym) + go4(xi,xf,id+1,yf,ym); debug("tchau 4\n"); return ans; } ll go3(int xi,int xf,int yi,int yf,int ym){ if(xi == 0 || xf == n-1) return 0; if(xi > xf) return 0; int A = ym, B = ym; debug("oi x: %d~%d y: %d~%d quebra A ? B ?\n",xi,xf,yi,yf); if(RMQ[1][ym].val(xi,xf) >= min(M[xi-1][ym],M[xf+1][ym])) return 0; while(1){ A--; if(A == 0 || A < yi) break; debug("A %d\n",A); int ok = 1; //for(int i=xi;i<=xf;i++) // if(M[i][A] >= M[xi-1][A] || M[i][A] >= M[xf+1][A]) ok = 0; if(RMQ[1][A].val(xi,xf) >= min(M[xi-1][A],M[xf+1][A])) ok = 0; if(ok == 0) break; } A++; while(1){ B++; if(B == m-1 || B > yf) break; int ok = 1; for(int i=xi;i<=xf;i++) if(M[i][B] >= M[xi-1][B] || M[i][B] >= M[xf+1][B]) ok = 0; if(ok == 0) break; } B--; debug("go3 x: %d~%d y: %d~%d quebra A %d B %d\n",xi,xf,yi,yf,A,B); return go4(xi,xf,A,B,ym); } ll go2(int xi,int xf,int yi,int yf,int ym){ if(xi > xf) return 0; if(yi > yf) return 0; if(ym == 0 || ym == m-1) return 0; debug("go2 x %d~%d y %d~%d\n",xi,xf,yi,yf); int mx = -1, id = -1; /*for(int i=xi;i<=xf;i++) if(M[i][ym] > mx){ mx = M[i][ym]; id = i; }*/ id = RMQ[1][ym].pos(xi,xf); ll ans = go3(xi,id-1,yi,yf,ym) + go3(id+1,xf,yi,yf,ym) + go2(xi,id-1,yi,yf,ym) + go2(id+1,xf,yi,yf,ym); return ans; } ll go(int yi,int yf){ if(yi > yf) return 0; int ym = (yi+yf)/2; debug("oi\n"); ll ans = go(yi,ym-1) + go(ym+1,yf) + go2(0,n-1,yi,yf,ym); return ans; } long long count_rectangles(std::vector<std::vector<int> > a) { n = a.size(); m = a[0].size(); for(int i=0;i<n;i++) for(int j=0;j<m;j++) M[i][j] = a[i][j]; for(int i=0;i<n;i++){ RMQ[0][i].len = m; for(int j=0;j<m;j++) RMQ[0][i].arr[j] = M[i][j]; RMQ[0][i].build(); } for(int j=0;j<m;j++){ RMQ[1][j].len = n; for(int i=0;i<n;i++) RMQ[1][j].arr[i] = M[i][j]; RMQ[1][j].build(); } return go(0,m-1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1016 KB | Output is correct |
2 | Correct | 5 ms | 3960 KB | Output is correct |
3 | Correct | 5 ms | 3832 KB | Output is correct |
4 | Correct | 5 ms | 3832 KB | Output is correct |
5 | Correct | 5 ms | 3960 KB | Output is correct |
6 | Correct | 5 ms | 3832 KB | Output is correct |
7 | Correct | 4 ms | 2936 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 3964 KB | Output is correct |
10 | Correct | 5 ms | 3960 KB | Output is correct |
11 | Correct | 5 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3960 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 1016 KB | Output is correct |
15 | Correct | 3 ms | 1400 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 632 KB | Output is correct |
19 | Correct | 5 ms | 3960 KB | Output is correct |
20 | Correct | 4 ms | 3064 KB | Output is correct |
21 | Correct | 2 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1016 KB | Output is correct |
2 | Correct | 5 ms | 3960 KB | Output is correct |
3 | Correct | 5 ms | 3832 KB | Output is correct |
4 | Correct | 5 ms | 3832 KB | Output is correct |
5 | Correct | 5 ms | 3960 KB | Output is correct |
6 | Correct | 5 ms | 3832 KB | Output is correct |
7 | Correct | 4 ms | 2936 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 3964 KB | Output is correct |
10 | Correct | 5 ms | 3960 KB | Output is correct |
11 | Correct | 5 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3960 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 1016 KB | Output is correct |
15 | Correct | 3 ms | 1400 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 13 ms | 10104 KB | Output is correct |
18 | Correct | 12 ms | 10104 KB | Output is correct |
19 | Correct | 12 ms | 10104 KB | Output is correct |
20 | Correct | 10 ms | 10048 KB | Output is correct |
21 | Correct | 10 ms | 9980 KB | Output is correct |
22 | Correct | 10 ms | 9976 KB | Output is correct |
23 | Correct | 11 ms | 10104 KB | Output is correct |
24 | Correct | 10 ms | 7672 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 632 KB | Output is correct |
27 | Correct | 5 ms | 3960 KB | Output is correct |
28 | Correct | 4 ms | 3064 KB | Output is correct |
29 | Correct | 2 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1016 KB | Output is correct |
2 | Correct | 5 ms | 3960 KB | Output is correct |
3 | Correct | 5 ms | 3832 KB | Output is correct |
4 | Correct | 5 ms | 3832 KB | Output is correct |
5 | Correct | 5 ms | 3960 KB | Output is correct |
6 | Correct | 5 ms | 3832 KB | Output is correct |
7 | Correct | 4 ms | 2936 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 3964 KB | Output is correct |
10 | Correct | 5 ms | 3960 KB | Output is correct |
11 | Correct | 5 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3960 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 1016 KB | Output is correct |
15 | Correct | 3 ms | 1400 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 13 ms | 10104 KB | Output is correct |
18 | Correct | 12 ms | 10104 KB | Output is correct |
19 | Correct | 12 ms | 10104 KB | Output is correct |
20 | Correct | 10 ms | 10048 KB | Output is correct |
21 | Correct | 10 ms | 9980 KB | Output is correct |
22 | Correct | 10 ms | 9976 KB | Output is correct |
23 | Correct | 11 ms | 10104 KB | Output is correct |
24 | Correct | 10 ms | 7672 KB | Output is correct |
25 | Correct | 76 ms | 26384 KB | Output is correct |
26 | Correct | 82 ms | 26436 KB | Output is correct |
27 | Correct | 76 ms | 26360 KB | Output is correct |
28 | Correct | 30 ms | 26492 KB | Output is correct |
29 | Correct | 35 ms | 26360 KB | Output is correct |
30 | Correct | 31 ms | 26360 KB | Output is correct |
31 | Correct | 36 ms | 26464 KB | Output is correct |
32 | Correct | 35 ms | 26232 KB | Output is correct |
33 | Correct | 2 ms | 376 KB | Output is correct |
34 | Correct | 2 ms | 632 KB | Output is correct |
35 | Correct | 5 ms | 3960 KB | Output is correct |
36 | Correct | 4 ms | 3064 KB | Output is correct |
37 | Correct | 2 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1016 KB | Output is correct |
2 | Correct | 5 ms | 3960 KB | Output is correct |
3 | Correct | 5 ms | 3832 KB | Output is correct |
4 | Correct | 5 ms | 3832 KB | Output is correct |
5 | Correct | 5 ms | 3960 KB | Output is correct |
6 | Correct | 5 ms | 3832 KB | Output is correct |
7 | Correct | 4 ms | 2936 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 3964 KB | Output is correct |
10 | Correct | 5 ms | 3960 KB | Output is correct |
11 | Correct | 5 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3960 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 1016 KB | Output is correct |
15 | Correct | 3 ms | 1400 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 13 ms | 10104 KB | Output is correct |
18 | Correct | 12 ms | 10104 KB | Output is correct |
19 | Correct | 12 ms | 10104 KB | Output is correct |
20 | Correct | 10 ms | 10048 KB | Output is correct |
21 | Correct | 10 ms | 9980 KB | Output is correct |
22 | Correct | 10 ms | 9976 KB | Output is correct |
23 | Correct | 11 ms | 10104 KB | Output is correct |
24 | Correct | 10 ms | 7672 KB | Output is correct |
25 | Correct | 76 ms | 26384 KB | Output is correct |
26 | Correct | 82 ms | 26436 KB | Output is correct |
27 | Correct | 76 ms | 26360 KB | Output is correct |
28 | Correct | 30 ms | 26492 KB | Output is correct |
29 | Correct | 35 ms | 26360 KB | Output is correct |
30 | Correct | 31 ms | 26360 KB | Output is correct |
31 | Correct | 36 ms | 26464 KB | Output is correct |
32 | Correct | 35 ms | 26232 KB | Output is correct |
33 | Correct | 205 ms | 108388 KB | Output is correct |
34 | Correct | 215 ms | 108480 KB | Output is correct |
35 | Correct | 186 ms | 108536 KB | Output is correct |
36 | Correct | 207 ms | 108424 KB | Output is correct |
37 | Correct | 4919 ms | 108408 KB | Output is correct |
38 | Correct | 4817 ms | 109764 KB | Output is correct |
39 | Correct | 4802 ms | 109816 KB | Output is correct |
40 | Correct | 4008 ms | 105940 KB | Output is correct |
41 | Correct | 157 ms | 109304 KB | Output is correct |
42 | Correct | 171 ms | 109404 KB | Output is correct |
43 | Correct | 253 ms | 110044 KB | Output is correct |
44 | Correct | 223 ms | 109816 KB | Output is correct |
45 | Correct | 131 ms | 79096 KB | Output is correct |
46 | Correct | 122 ms | 77652 KB | Output is correct |
47 | Correct | 236 ms | 110064 KB | Output is correct |
48 | Correct | 254 ms | 109860 KB | Output is correct |
49 | Correct | 2 ms | 376 KB | Output is correct |
50 | Correct | 2 ms | 632 KB | Output is correct |
51 | Correct | 5 ms | 3960 KB | Output is correct |
52 | Correct | 4 ms | 3064 KB | Output is correct |
53 | Correct | 2 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 141176 KB | Output is correct |
2 | Correct | 91 ms | 120036 KB | Output is correct |
3 | Correct | 105 ms | 141176 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 111 ms | 141304 KB | Output is correct |
6 | Correct | 108 ms | 141304 KB | Output is correct |
7 | Correct | 124 ms | 141148 KB | Output is correct |
8 | Correct | 111 ms | 141236 KB | Output is correct |
9 | Correct | 106 ms | 141176 KB | Output is correct |
10 | Correct | 104 ms | 140920 KB | Output is correct |
11 | Correct | 105 ms | 141048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 714 ms | 296184 KB | Output is correct |
3 | Correct | 1434 ms | 443764 KB | Output is correct |
4 | Correct | 1443 ms | 444920 KB | Output is correct |
5 | Correct | 1406 ms | 445052 KB | Output is correct |
6 | Correct | 627 ms | 311160 KB | Output is correct |
7 | Correct | 1090 ms | 430584 KB | Output is correct |
8 | Correct | 1178 ms | 445128 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 632 KB | Output is correct |
11 | Correct | 5 ms | 3960 KB | Output is correct |
12 | Correct | 4 ms | 3064 KB | Output is correct |
13 | Correct | 2 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1016 KB | Output is correct |
2 | Correct | 5 ms | 3960 KB | Output is correct |
3 | Correct | 5 ms | 3832 KB | Output is correct |
4 | Correct | 5 ms | 3832 KB | Output is correct |
5 | Correct | 5 ms | 3960 KB | Output is correct |
6 | Correct | 5 ms | 3832 KB | Output is correct |
7 | Correct | 4 ms | 2936 KB | Output is correct |
8 | Correct | 4 ms | 2808 KB | Output is correct |
9 | Correct | 5 ms | 3964 KB | Output is correct |
10 | Correct | 5 ms | 3960 KB | Output is correct |
11 | Correct | 5 ms | 3832 KB | Output is correct |
12 | Correct | 5 ms | 3960 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 1016 KB | Output is correct |
15 | Correct | 3 ms | 1400 KB | Output is correct |
16 | Correct | 2 ms | 760 KB | Output is correct |
17 | Correct | 13 ms | 10104 KB | Output is correct |
18 | Correct | 12 ms | 10104 KB | Output is correct |
19 | Correct | 12 ms | 10104 KB | Output is correct |
20 | Correct | 10 ms | 10048 KB | Output is correct |
21 | Correct | 10 ms | 9980 KB | Output is correct |
22 | Correct | 10 ms | 9976 KB | Output is correct |
23 | Correct | 11 ms | 10104 KB | Output is correct |
24 | Correct | 10 ms | 7672 KB | Output is correct |
25 | Correct | 76 ms | 26384 KB | Output is correct |
26 | Correct | 82 ms | 26436 KB | Output is correct |
27 | Correct | 76 ms | 26360 KB | Output is correct |
28 | Correct | 30 ms | 26492 KB | Output is correct |
29 | Correct | 35 ms | 26360 KB | Output is correct |
30 | Correct | 31 ms | 26360 KB | Output is correct |
31 | Correct | 36 ms | 26464 KB | Output is correct |
32 | Correct | 35 ms | 26232 KB | Output is correct |
33 | Correct | 205 ms | 108388 KB | Output is correct |
34 | Correct | 215 ms | 108480 KB | Output is correct |
35 | Correct | 186 ms | 108536 KB | Output is correct |
36 | Correct | 207 ms | 108424 KB | Output is correct |
37 | Correct | 4919 ms | 108408 KB | Output is correct |
38 | Correct | 4817 ms | 109764 KB | Output is correct |
39 | Correct | 4802 ms | 109816 KB | Output is correct |
40 | Correct | 4008 ms | 105940 KB | Output is correct |
41 | Correct | 157 ms | 109304 KB | Output is correct |
42 | Correct | 171 ms | 109404 KB | Output is correct |
43 | Correct | 253 ms | 110044 KB | Output is correct |
44 | Correct | 223 ms | 109816 KB | Output is correct |
45 | Correct | 131 ms | 79096 KB | Output is correct |
46 | Correct | 122 ms | 77652 KB | Output is correct |
47 | Correct | 236 ms | 110064 KB | Output is correct |
48 | Correct | 254 ms | 109860 KB | Output is correct |
49 | Correct | 106 ms | 141176 KB | Output is correct |
50 | Correct | 91 ms | 120036 KB | Output is correct |
51 | Correct | 105 ms | 141176 KB | Output is correct |
52 | Correct | 2 ms | 504 KB | Output is correct |
53 | Correct | 111 ms | 141304 KB | Output is correct |
54 | Correct | 108 ms | 141304 KB | Output is correct |
55 | Correct | 124 ms | 141148 KB | Output is correct |
56 | Correct | 111 ms | 141236 KB | Output is correct |
57 | Correct | 106 ms | 141176 KB | Output is correct |
58 | Correct | 104 ms | 140920 KB | Output is correct |
59 | Correct | 105 ms | 141048 KB | Output is correct |
60 | Correct | 3 ms | 1528 KB | Output is correct |
61 | Correct | 714 ms | 296184 KB | Output is correct |
62 | Correct | 1434 ms | 443764 KB | Output is correct |
63 | Correct | 1443 ms | 444920 KB | Output is correct |
64 | Correct | 1406 ms | 445052 KB | Output is correct |
65 | Correct | 627 ms | 311160 KB | Output is correct |
66 | Correct | 1090 ms | 430584 KB | Output is correct |
67 | Correct | 1178 ms | 445128 KB | Output is correct |
68 | Execution timed out | 5127 ms | 492000 KB | Time limit exceeded |
69 | Halted | 0 ms | 0 KB | - |