# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
906280 |
2024-01-13T22:45:14 Z |
vjudge1 |
Rectangles (IOI19_rect) |
C++17 |
|
2221 ms |
1048576 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
long long count_rectangles(std::vector<std::vector<int> > a) {
int n = sz(a);
int m = sz(a[0]);
vector<vector<map<int,int>>> rowf(n,vector<map<int,int>>(m));
rep(i,0,n){
vector<pii> stack;
rep(j,0,m){
while(sz(stack) && stack.back().F < a[i][j]){
if(stack.back().S+1 <= j-1) {
rowf[i][stack.back().S+1][j-1]=-1;
// cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl;
}
stack.pop_back();
}
if(sz(stack) && stack.back().S+1 <= j-1) {
// cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl;
rowf[i][stack.back().S+1][j-1]=-1;
}
while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back();
stack.pb({a[i][j],j});
}
}
vector<vector<map<int,int>>> colf(n,vector<map<int,int>>(m));
rep(j,0,m){
vector<pii> stack;
rep(i,0,n){
while(sz(stack) && stack.back().F < a[i][j]){
if(stack.back().S+1<=i-1) colf[stack.back().S+1][j][i-1]=-1;
stack.pop_back();
}
if(sz(stack) && stack.back().S+1<=i-1) colf[stack.back().S+1][j][i-1]=-1;
while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back();
stack.pb({a[i][j],i});
}
}
rep(i,0,n)rep(j,0,m){
for(auto p : rowf[i][j]){
if(p.S == -1){
int k = i;
while(k<n && rowf[k][j].count(p.F)) k++;
rep(l,i,k) rowf[l][j][p.F]=k-1;
}
}
for(auto p : colf[i][j]){
if(p.S == -1){
int k = j;
while(k<m && colf[i][k].count(p.F)) k++;
rep(l,j,k) colf[i][l][p.F]=k-1;
}
}
}
// rep(i,0,n){
// rep(j,0,m){
// cout<<i<<' '<<j<<" rows:";
// for(pii x : rowf[i][j]) cout<<' '<<x.F<<","<<x.S;
// cout<<endl;
// cout<<i<<' '<<j<<" cols:";
// for(pii x : colf[i][j]) cout<<' '<<x.F<<","<<x.S;
// cout<<endl;
// }
// }
ll ans = 0;
rep(i,0,n){
rep(j,0,m){
for(pii l : colf[i][j])for(pii r : rowf[i][j]){
// [i, r.F], r.S tells how far we go on other
// [j, l.F], l.S tells how far we go on other
if(l.S < r.F) break;
bool good = l.S>=r.F && r.S >= l.F;
// cout<<i<<' '<<j<<" ("<<l.F<<','<<l.S<<") ("<<r.F<<','<<r.S<<") "<<good<<endl;
ans += good;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
1628 KB |
Output is correct |
23 |
Correct |
2 ms |
1628 KB |
Output is correct |
24 |
Correct |
2 ms |
1628 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
3 ms |
1372 KB |
Output is correct |
27 |
Correct |
3 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1372 KB |
Output is correct |
29 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1372 KB |
Output is correct |
22 |
Correct |
3 ms |
1372 KB |
Output is correct |
23 |
Correct |
3 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
12 ms |
8028 KB |
Output is correct |
31 |
Correct |
13 ms |
8028 KB |
Output is correct |
32 |
Correct |
13 ms |
8028 KB |
Output is correct |
33 |
Correct |
8 ms |
5720 KB |
Output is correct |
34 |
Correct |
14 ms |
8040 KB |
Output is correct |
35 |
Correct |
16 ms |
8028 KB |
Output is correct |
36 |
Correct |
15 ms |
7840 KB |
Output is correct |
37 |
Correct |
14 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1372 KB |
Output is correct |
22 |
Correct |
3 ms |
1372 KB |
Output is correct |
23 |
Correct |
3 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
12 ms |
8028 KB |
Output is correct |
26 |
Correct |
13 ms |
8028 KB |
Output is correct |
27 |
Correct |
13 ms |
8028 KB |
Output is correct |
28 |
Correct |
8 ms |
5720 KB |
Output is correct |
29 |
Correct |
14 ms |
8040 KB |
Output is correct |
30 |
Correct |
16 ms |
8028 KB |
Output is correct |
31 |
Correct |
15 ms |
7840 KB |
Output is correct |
32 |
Correct |
14 ms |
7512 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
122 ms |
73296 KB |
Output is correct |
39 |
Correct |
148 ms |
73088 KB |
Output is correct |
40 |
Correct |
120 ms |
73300 KB |
Output is correct |
41 |
Correct |
161 ms |
73324 KB |
Output is correct |
42 |
Correct |
200 ms |
96028 KB |
Output is correct |
43 |
Correct |
197 ms |
96096 KB |
Output is correct |
44 |
Correct |
200 ms |
96044 KB |
Output is correct |
45 |
Correct |
179 ms |
89680 KB |
Output is correct |
46 |
Correct |
110 ms |
61780 KB |
Output is correct |
47 |
Correct |
123 ms |
68176 KB |
Output is correct |
48 |
Correct |
239 ms |
94904 KB |
Output is correct |
49 |
Correct |
253 ms |
95296 KB |
Output is correct |
50 |
Correct |
115 ms |
47704 KB |
Output is correct |
51 |
Correct |
125 ms |
47844 KB |
Output is correct |
52 |
Correct |
232 ms |
91660 KB |
Output is correct |
53 |
Correct |
230 ms |
91868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1692 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
2 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
712 ms |
359168 KB |
Output is correct |
8 |
Correct |
1465 ms |
779228 KB |
Output is correct |
9 |
Correct |
1511 ms |
782808 KB |
Output is correct |
10 |
Correct |
1514 ms |
783124 KB |
Output is correct |
11 |
Correct |
293 ms |
314960 KB |
Output is correct |
12 |
Correct |
565 ms |
597512 KB |
Output is correct |
13 |
Correct |
629 ms |
636976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1372 KB |
Output is correct |
22 |
Correct |
3 ms |
1372 KB |
Output is correct |
23 |
Correct |
3 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
12 ms |
8028 KB |
Output is correct |
26 |
Correct |
13 ms |
8028 KB |
Output is correct |
27 |
Correct |
13 ms |
8028 KB |
Output is correct |
28 |
Correct |
8 ms |
5720 KB |
Output is correct |
29 |
Correct |
14 ms |
8040 KB |
Output is correct |
30 |
Correct |
16 ms |
8028 KB |
Output is correct |
31 |
Correct |
15 ms |
7840 KB |
Output is correct |
32 |
Correct |
14 ms |
7512 KB |
Output is correct |
33 |
Correct |
122 ms |
73296 KB |
Output is correct |
34 |
Correct |
148 ms |
73088 KB |
Output is correct |
35 |
Correct |
120 ms |
73300 KB |
Output is correct |
36 |
Correct |
161 ms |
73324 KB |
Output is correct |
37 |
Correct |
200 ms |
96028 KB |
Output is correct |
38 |
Correct |
197 ms |
96096 KB |
Output is correct |
39 |
Correct |
200 ms |
96044 KB |
Output is correct |
40 |
Correct |
179 ms |
89680 KB |
Output is correct |
41 |
Correct |
110 ms |
61780 KB |
Output is correct |
42 |
Correct |
123 ms |
68176 KB |
Output is correct |
43 |
Correct |
239 ms |
94904 KB |
Output is correct |
44 |
Correct |
253 ms |
95296 KB |
Output is correct |
45 |
Correct |
115 ms |
47704 KB |
Output is correct |
46 |
Correct |
125 ms |
47844 KB |
Output is correct |
47 |
Correct |
232 ms |
91660 KB |
Output is correct |
48 |
Correct |
230 ms |
91868 KB |
Output is correct |
49 |
Correct |
3 ms |
1692 KB |
Output is correct |
50 |
Correct |
2 ms |
1372 KB |
Output is correct |
51 |
Correct |
1 ms |
1116 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
2 ms |
1628 KB |
Output is correct |
54 |
Correct |
2 ms |
1628 KB |
Output is correct |
55 |
Correct |
2 ms |
1628 KB |
Output is correct |
56 |
Correct |
2 ms |
1628 KB |
Output is correct |
57 |
Correct |
2 ms |
1628 KB |
Output is correct |
58 |
Correct |
1 ms |
860 KB |
Output is correct |
59 |
Correct |
2 ms |
1116 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
712 ms |
359168 KB |
Output is correct |
62 |
Correct |
1465 ms |
779228 KB |
Output is correct |
63 |
Correct |
1511 ms |
782808 KB |
Output is correct |
64 |
Correct |
1514 ms |
783124 KB |
Output is correct |
65 |
Correct |
293 ms |
314960 KB |
Output is correct |
66 |
Correct |
565 ms |
597512 KB |
Output is correct |
67 |
Correct |
629 ms |
636976 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
0 ms |
348 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
1956 ms |
930384 KB |
Output is correct |
74 |
Correct |
2221 ms |
930072 KB |
Output is correct |
75 |
Correct |
1748 ms |
929976 KB |
Output is correct |
76 |
Correct |
2175 ms |
930136 KB |
Output is correct |
77 |
Runtime error |
1166 ms |
1048576 KB |
Execution killed with signal 9 |
78 |
Halted |
0 ms |
0 KB |
- |