# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153570 | 2019-09-14T16:05:01 Z | myungwoo | Rectangles (IOI19_rect) | C++14 | 5000 ms | 335584 KB |
#include <bits/stdc++.h> #include "rect.h" using namespace std; #define fr first #define sc second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() typedef long long lld; typedef pair<int, int> pii; int N, M; int A[2502][2502]; pii ver[2502][2502], hor[2502][2502]; struct SEGMENT { short a, b, t, dp; bool operator < (const SEGMENT &ot)const{ if (t != ot.t) return t < ot.t; if (a != ot.a) return a < ot.a; return b < ot.b; } bool operator == (const SEGMENT &ot)const{ return a == ot.a && b == ot.b && t == ot.t; } bool operator != (const SEGMENT &ot)const{ return a != ot.a || b != ot.b || t != ot.t; } }; struct RECT { short a, b, c, d; bool operator < (const RECT &ot)const{ if (a != ot.a) return a < ot.a; if (b != ot.b) return b < ot.b; if (c != ot.c) return c < ot.c; return d < ot.d; } bool operator != (const RECT &ot)const{ return a != ot.a || b != ot.b || c != ot.c || d != ot.d; } }; lld count_rectangles(vector<vector<int>> a) { N = sz(a); M = sz(a[0]); for (int i=1;i<=N;i++) for (int j=1;j<=M;j++) A[i][j] = a[i-1][j-1]; vector <SEGMENT> vertical, horizontal; for (int i=1;i<=N;i++){ { stack <int> stk; for (int j=1;j<=M;j++){ while (!stk.empty() && A[i][stk.top()] <= A[i][j]) stk.pop(); hor[i][j].fr = stk.empty() ? 1 : stk.top()+1; stk.push(j); } } { stack <int> stk; for (int j=M;j;j--){ while (!stk.empty() && A[i][stk.top()] <= A[i][j]) stk.pop(); hor[i][j].sc = stk.empty() ? M : stk.top()-1; stk.push(j); } } } for (int j=1;j<=M;j++){ { stack <int> stk; for (int i=1;i<=N;i++){ while (!stk.empty() && A[stk.top()][j] <= A[i][j]) stk.pop(); ver[i][j].fr = stk.empty() ? 1 : stk.top()+1; stk.push(i); } } { stack <int> stk; for (int i=N;i;i--){ while (!stk.empty() && A[stk.top()][j] <= A[i][j]) stk.pop(); ver[i][j].sc = stk.empty() ? N : stk.top()-1; stk.push(i); } } } for (int i=1;i<=N;i++) for (int j=1;j<=M;j++){ horizontal.pb({hor[i][j].fr, hor[i][j].sc, i}); vertical.pb({ver[i][j].fr, ver[i][j].sc, j}); } sort(all(horizontal)); sort(all(vertical)); for (auto i=horizontal.begin(),j=i;i!=horizontal.end();i++){ while (*j < SEGMENT{i->a, i->b, i->t-1}) j++; if (*j == SEGMENT{i->a, i->b, i->t-1}) i->dp = j->dp+1; else i->dp = 1; } for (auto i=vertical.begin(),j=i;i!=vertical.end();i++){ while (*j < SEGMENT{i->a, i->b, i->t-1}) j++; if (*j == SEGMENT{i->a, i->b, i->t-1}) i->dp = j->dp+1; else i->dp = 1; } vector <RECT> rects; for (int i=1;i<=N;i++) for (int j=1;j<=M;j++){ int sy = ver[i][j].fr, ey = ver[i][j].sc; int sx = hor[i][j].fr, ex = hor[i][j].sc; if (sy == 1 || sx == 1 || ey == N || ex == M) continue; { auto it = lower_bound(all(vertical), SEGMENT{sy, ey, ex}); if (it == vertical.end() || *it != SEGMENT{sy, ey, ex} || it->dp <= ex-sx) continue; } { auto it = lower_bound(all(horizontal), SEGMENT{sx, ex, ey}); if (it == horizontal.end() || *it != SEGMENT{sx, ex, ey} || it->dp <= ey-sy) continue; } rects.pb({sy, sx, ey, ex}); } sort(all(rects)); int ans = 0; for (int i=0;i<sz(rects);i++) if (i == 0 || rects[i-1] != rects[i]) ans++; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 760 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 3 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 760 KB | Output is correct |
10 | Correct | 3 ms | 760 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 3 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 356 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 3 ms | 760 KB | Output is correct |
20 | Correct | 2 ms | 760 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 760 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 3 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 760 KB | Output is correct |
10 | Correct | 3 ms | 760 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 3 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 356 KB | Output is correct |
17 | Correct | 4 ms | 1656 KB | Output is correct |
18 | Correct | 6 ms | 1656 KB | Output is correct |
19 | Correct | 6 ms | 1656 KB | Output is correct |
20 | Correct | 5 ms | 1656 KB | Output is correct |
21 | Correct | 6 ms | 1656 KB | Output is correct |
22 | Correct | 6 ms | 1596 KB | Output is correct |
23 | Correct | 6 ms | 1656 KB | Output is correct |
24 | Correct | 5 ms | 1528 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 3 ms | 760 KB | Output is correct |
28 | Correct | 2 ms | 760 KB | Output is correct |
29 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 760 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 3 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 760 KB | Output is correct |
10 | Correct | 3 ms | 760 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 3 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 356 KB | Output is correct |
17 | Correct | 4 ms | 1656 KB | Output is correct |
18 | Correct | 6 ms | 1656 KB | Output is correct |
19 | Correct | 6 ms | 1656 KB | Output is correct |
20 | Correct | 5 ms | 1656 KB | Output is correct |
21 | Correct | 6 ms | 1656 KB | Output is correct |
22 | Correct | 6 ms | 1596 KB | Output is correct |
23 | Correct | 6 ms | 1656 KB | Output is correct |
24 | Correct | 5 ms | 1528 KB | Output is correct |
25 | Correct | 21 ms | 5224 KB | Output is correct |
26 | Correct | 21 ms | 5200 KB | Output is correct |
27 | Correct | 22 ms | 5352 KB | Output is correct |
28 | Correct | 22 ms | 4852 KB | Output is correct |
29 | Correct | 27 ms | 4856 KB | Output is correct |
30 | Correct | 28 ms | 4852 KB | Output is correct |
31 | Correct | 28 ms | 4916 KB | Output is correct |
32 | Correct | 28 ms | 4808 KB | Output is correct |
33 | Correct | 2 ms | 376 KB | Output is correct |
34 | Correct | 2 ms | 376 KB | Output is correct |
35 | Correct | 3 ms | 760 KB | Output is correct |
36 | Correct | 2 ms | 760 KB | Output is correct |
37 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 760 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 3 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 760 KB | Output is correct |
10 | Correct | 3 ms | 760 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 3 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 356 KB | Output is correct |
17 | Correct | 4 ms | 1656 KB | Output is correct |
18 | Correct | 6 ms | 1656 KB | Output is correct |
19 | Correct | 6 ms | 1656 KB | Output is correct |
20 | Correct | 5 ms | 1656 KB | Output is correct |
21 | Correct | 6 ms | 1656 KB | Output is correct |
22 | Correct | 6 ms | 1596 KB | Output is correct |
23 | Correct | 6 ms | 1656 KB | Output is correct |
24 | Correct | 5 ms | 1528 KB | Output is correct |
25 | Correct | 21 ms | 5224 KB | Output is correct |
26 | Correct | 21 ms | 5200 KB | Output is correct |
27 | Correct | 22 ms | 5352 KB | Output is correct |
28 | Correct | 22 ms | 4852 KB | Output is correct |
29 | Correct | 27 ms | 4856 KB | Output is correct |
30 | Correct | 28 ms | 4852 KB | Output is correct |
31 | Correct | 28 ms | 4916 KB | Output is correct |
32 | Correct | 28 ms | 4808 KB | Output is correct |
33 | Correct | 162 ms | 30128 KB | Output is correct |
34 | Correct | 156 ms | 30280 KB | Output is correct |
35 | Correct | 165 ms | 30160 KB | Output is correct |
36 | Correct | 149 ms | 30156 KB | Output is correct |
37 | Correct | 255 ms | 36092 KB | Output is correct |
38 | Correct | 259 ms | 36132 KB | Output is correct |
39 | Correct | 257 ms | 36032 KB | Output is correct |
40 | Correct | 241 ms | 34120 KB | Output is correct |
41 | Correct | 226 ms | 30456 KB | Output is correct |
42 | Correct | 261 ms | 30968 KB | Output is correct |
43 | Correct | 358 ms | 33228 KB | Output is correct |
44 | Correct | 349 ms | 33356 KB | Output is correct |
45 | Correct | 178 ms | 21080 KB | Output is correct |
46 | Correct | 168 ms | 16812 KB | Output is correct |
47 | Correct | 363 ms | 33960 KB | Output is correct |
48 | Correct | 366 ms | 33876 KB | Output is correct |
49 | Correct | 2 ms | 376 KB | Output is correct |
50 | Correct | 2 ms | 376 KB | Output is correct |
51 | Correct | 3 ms | 760 KB | Output is correct |
52 | Correct | 2 ms | 760 KB | Output is correct |
53 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 760 KB | Output is correct |
2 | Correct | 5 ms | 676 KB | Output is correct |
3 | Correct | 4 ms | 760 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 632 KB | Output is correct |
6 | Correct | 5 ms | 760 KB | Output is correct |
7 | Correct | 5 ms | 688 KB | Output is correct |
8 | Correct | 5 ms | 692 KB | Output is correct |
9 | Correct | 5 ms | 688 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 4 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 1506 ms | 132792 KB | Output is correct |
3 | Correct | 3484 ms | 275068 KB | Output is correct |
4 | Correct | 3473 ms | 276264 KB | Output is correct |
5 | Correct | 3488 ms | 276488 KB | Output is correct |
6 | Correct | 792 ms | 134532 KB | Output is correct |
7 | Correct | 1598 ms | 267576 KB | Output is correct |
8 | Correct | 1670 ms | 270688 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 2 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 760 KB | Output is correct |
4 | Correct | 3 ms | 760 KB | Output is correct |
5 | Correct | 3 ms | 760 KB | Output is correct |
6 | Correct | 3 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 760 KB | Output is correct |
10 | Correct | 3 ms | 760 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 3 ms | 760 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 504 KB | Output is correct |
16 | Correct | 2 ms | 356 KB | Output is correct |
17 | Correct | 4 ms | 1656 KB | Output is correct |
18 | Correct | 6 ms | 1656 KB | Output is correct |
19 | Correct | 6 ms | 1656 KB | Output is correct |
20 | Correct | 5 ms | 1656 KB | Output is correct |
21 | Correct | 6 ms | 1656 KB | Output is correct |
22 | Correct | 6 ms | 1596 KB | Output is correct |
23 | Correct | 6 ms | 1656 KB | Output is correct |
24 | Correct | 5 ms | 1528 KB | Output is correct |
25 | Correct | 21 ms | 5224 KB | Output is correct |
26 | Correct | 21 ms | 5200 KB | Output is correct |
27 | Correct | 22 ms | 5352 KB | Output is correct |
28 | Correct | 22 ms | 4852 KB | Output is correct |
29 | Correct | 27 ms | 4856 KB | Output is correct |
30 | Correct | 28 ms | 4852 KB | Output is correct |
31 | Correct | 28 ms | 4916 KB | Output is correct |
32 | Correct | 28 ms | 4808 KB | Output is correct |
33 | Correct | 162 ms | 30128 KB | Output is correct |
34 | Correct | 156 ms | 30280 KB | Output is correct |
35 | Correct | 165 ms | 30160 KB | Output is correct |
36 | Correct | 149 ms | 30156 KB | Output is correct |
37 | Correct | 255 ms | 36092 KB | Output is correct |
38 | Correct | 259 ms | 36132 KB | Output is correct |
39 | Correct | 257 ms | 36032 KB | Output is correct |
40 | Correct | 241 ms | 34120 KB | Output is correct |
41 | Correct | 226 ms | 30456 KB | Output is correct |
42 | Correct | 261 ms | 30968 KB | Output is correct |
43 | Correct | 358 ms | 33228 KB | Output is correct |
44 | Correct | 349 ms | 33356 KB | Output is correct |
45 | Correct | 178 ms | 21080 KB | Output is correct |
46 | Correct | 168 ms | 16812 KB | Output is correct |
47 | Correct | 363 ms | 33960 KB | Output is correct |
48 | Correct | 366 ms | 33876 KB | Output is correct |
49 | Correct | 5 ms | 760 KB | Output is correct |
50 | Correct | 5 ms | 676 KB | Output is correct |
51 | Correct | 4 ms | 760 KB | Output is correct |
52 | Correct | 2 ms | 376 KB | Output is correct |
53 | Correct | 5 ms | 632 KB | Output is correct |
54 | Correct | 5 ms | 760 KB | Output is correct |
55 | Correct | 5 ms | 688 KB | Output is correct |
56 | Correct | 5 ms | 692 KB | Output is correct |
57 | Correct | 5 ms | 688 KB | Output is correct |
58 | Correct | 3 ms | 504 KB | Output is correct |
59 | Correct | 4 ms | 632 KB | Output is correct |
60 | Correct | 2 ms | 504 KB | Output is correct |
61 | Correct | 1506 ms | 132792 KB | Output is correct |
62 | Correct | 3484 ms | 275068 KB | Output is correct |
63 | Correct | 3473 ms | 276264 KB | Output is correct |
64 | Correct | 3488 ms | 276488 KB | Output is correct |
65 | Correct | 792 ms | 134532 KB | Output is correct |
66 | Correct | 1598 ms | 267576 KB | Output is correct |
67 | Correct | 1670 ms | 270688 KB | Output is correct |
68 | Correct | 2519 ms | 270752 KB | Output is correct |
69 | Correct | 2303 ms | 270656 KB | Output is correct |
70 | Correct | 2474 ms | 270648 KB | Output is correct |
71 | Correct | 2366 ms | 270620 KB | Output is correct |
72 | Correct | 3783 ms | 335584 KB | Output is correct |
73 | Correct | 3108 ms | 188624 KB | Output is correct |
74 | Correct | 3311 ms | 226776 KB | Output is correct |
75 | Execution timed out | 5086 ms | 301720 KB | Time limit exceeded |
76 | Halted | 0 ms | 0 KB | - |