# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
928499 |
2024-02-16T13:31:24 Z |
knon0501 |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
365964 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> b[2505][2505];
vector<vector<int>> aa;
int f(int i,int j,int x,int y){
int cnt1 = 0;
int cnt2 = 0;
for(int k=i ; k<=j ; k++){
if(aa[x][k]<aa[y][k])
cnt1++;
if(aa[x][k]>aa[y][k])
cnt2++;
}
if(cnt1==j-i+1)return 1;
if(cnt2==j-i+1)return -1;
return 0;
}
long long count_rectangles(std::vector<std::vector<int> > a) {
aa=a;
int n = a.size();
int m = a[0].size();
for(int i=1 ; i<n-1 ; i++){
stack<int> S;
for(int j=0 ; j<m ; j++){
bool flag = true;
while(!S.empty() && a[i][S.top()] <= a[i][j]){
int x = S.top();
if(x +1 <j && flag)
b[x+1][j-1].push_back(i);
if(a[i][S.top()]==a[i][j])flag=false;
S.pop();
}
if(!S.empty() && flag){
int x = S.top();
if(x+1<j)
b[x+1][j-1].push_back(i);
}
S.push(j);
}
}
long long ans = 0;
for(int i=1 ; i<m ; i++){
for(int j=i ; j<m ; j++){
vector<vector<int>> c;
int prv=-1;
for(int x: b[i][j]){
// cout<<i<<" "<<j<<" "<<x<<endl;
if(prv+1<x)
c.push_back({x});
else
c.back().push_back(x);
prv=x;
}
for(auto d: c){
stack<int> S;
d.push_back(d.back()+1);
d.push_back(d[0]-1);
sort(d.begin(),d.end());
for(auto x: d){
bool flag = true;
while(!S.empty() && f(i,j,S.top(),x)>=0){
int k = S.top(); S.pop();
if(flag == false)continue;
if(f(i,j,k,x)==0 && k+1<x){
bool flag2 = true;
for(int l = k+1 ; l<x ; l++)
if(f(i,j,l,x)<=0)flag2 = false;
ans+=flag2;
flag=false;
}
else if(k +1 <x ){
ans++;
}
}
if(!S.empty() && S.top()+1<x && flag){
bool flag = true;
for(int l = S.top()+1 ; l<x ; l++)
if(f(i,j,l,x)<=0)flag = false;
ans+=flag;
}
S.push(x);
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147792 KB |
Output is correct |
3 |
Correct |
33 ms |
147792 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
32 ms |
147804 KB |
Output is correct |
7 |
Correct |
33 ms |
147800 KB |
Output is correct |
8 |
Correct |
32 ms |
147804 KB |
Output is correct |
9 |
Correct |
34 ms |
147668 KB |
Output is correct |
10 |
Correct |
36 ms |
147644 KB |
Output is correct |
11 |
Correct |
33 ms |
147792 KB |
Output is correct |
12 |
Correct |
35 ms |
147804 KB |
Output is correct |
13 |
Correct |
32 ms |
147548 KB |
Output is correct |
14 |
Correct |
33 ms |
147772 KB |
Output is correct |
15 |
Correct |
33 ms |
147556 KB |
Output is correct |
16 |
Correct |
34 ms |
147900 KB |
Output is correct |
17 |
Correct |
32 ms |
147536 KB |
Output is correct |
18 |
Correct |
33 ms |
147548 KB |
Output is correct |
19 |
Correct |
33 ms |
147804 KB |
Output is correct |
20 |
Correct |
32 ms |
147800 KB |
Output is correct |
21 |
Correct |
33 ms |
147540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147792 KB |
Output is correct |
3 |
Correct |
33 ms |
147792 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
32 ms |
147804 KB |
Output is correct |
7 |
Correct |
33 ms |
147800 KB |
Output is correct |
8 |
Correct |
32 ms |
147804 KB |
Output is correct |
9 |
Correct |
34 ms |
147668 KB |
Output is correct |
10 |
Correct |
36 ms |
147644 KB |
Output is correct |
11 |
Correct |
33 ms |
147792 KB |
Output is correct |
12 |
Correct |
35 ms |
147804 KB |
Output is correct |
13 |
Correct |
32 ms |
147548 KB |
Output is correct |
14 |
Correct |
33 ms |
147772 KB |
Output is correct |
15 |
Correct |
33 ms |
147556 KB |
Output is correct |
16 |
Correct |
34 ms |
147900 KB |
Output is correct |
17 |
Correct |
32 ms |
147536 KB |
Output is correct |
18 |
Correct |
33 ms |
147548 KB |
Output is correct |
19 |
Correct |
33 ms |
147804 KB |
Output is correct |
20 |
Correct |
32 ms |
147800 KB |
Output is correct |
21 |
Correct |
33 ms |
147540 KB |
Output is correct |
22 |
Correct |
33 ms |
147800 KB |
Output is correct |
23 |
Correct |
35 ms |
147780 KB |
Output is correct |
24 |
Correct |
34 ms |
147800 KB |
Output is correct |
25 |
Correct |
34 ms |
147804 KB |
Output is correct |
26 |
Correct |
36 ms |
147804 KB |
Output is correct |
27 |
Correct |
35 ms |
147804 KB |
Output is correct |
28 |
Correct |
39 ms |
147764 KB |
Output is correct |
29 |
Correct |
34 ms |
147792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147792 KB |
Output is correct |
3 |
Correct |
33 ms |
147792 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
32 ms |
147804 KB |
Output is correct |
7 |
Correct |
33 ms |
147800 KB |
Output is correct |
8 |
Correct |
32 ms |
147804 KB |
Output is correct |
9 |
Correct |
34 ms |
147668 KB |
Output is correct |
10 |
Correct |
36 ms |
147644 KB |
Output is correct |
11 |
Correct |
33 ms |
147792 KB |
Output is correct |
12 |
Correct |
35 ms |
147804 KB |
Output is correct |
13 |
Correct |
32 ms |
147548 KB |
Output is correct |
14 |
Correct |
33 ms |
147772 KB |
Output is correct |
15 |
Correct |
33 ms |
147556 KB |
Output is correct |
16 |
Correct |
34 ms |
147900 KB |
Output is correct |
17 |
Correct |
33 ms |
147800 KB |
Output is correct |
18 |
Correct |
35 ms |
147780 KB |
Output is correct |
19 |
Correct |
34 ms |
147800 KB |
Output is correct |
20 |
Correct |
34 ms |
147804 KB |
Output is correct |
21 |
Correct |
36 ms |
147804 KB |
Output is correct |
22 |
Correct |
35 ms |
147804 KB |
Output is correct |
23 |
Correct |
39 ms |
147764 KB |
Output is correct |
24 |
Correct |
34 ms |
147792 KB |
Output is correct |
25 |
Correct |
32 ms |
147536 KB |
Output is correct |
26 |
Correct |
33 ms |
147548 KB |
Output is correct |
27 |
Correct |
33 ms |
147804 KB |
Output is correct |
28 |
Correct |
32 ms |
147800 KB |
Output is correct |
29 |
Correct |
33 ms |
147540 KB |
Output is correct |
30 |
Correct |
43 ms |
148380 KB |
Output is correct |
31 |
Correct |
43 ms |
148508 KB |
Output is correct |
32 |
Correct |
43 ms |
148316 KB |
Output is correct |
33 |
Correct |
38 ms |
148312 KB |
Output is correct |
34 |
Correct |
45 ms |
148560 KB |
Output is correct |
35 |
Correct |
47 ms |
148560 KB |
Output is correct |
36 |
Correct |
59 ms |
148676 KB |
Output is correct |
37 |
Correct |
55 ms |
148464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147792 KB |
Output is correct |
3 |
Correct |
33 ms |
147792 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
32 ms |
147804 KB |
Output is correct |
7 |
Correct |
33 ms |
147800 KB |
Output is correct |
8 |
Correct |
32 ms |
147804 KB |
Output is correct |
9 |
Correct |
34 ms |
147668 KB |
Output is correct |
10 |
Correct |
36 ms |
147644 KB |
Output is correct |
11 |
Correct |
33 ms |
147792 KB |
Output is correct |
12 |
Correct |
35 ms |
147804 KB |
Output is correct |
13 |
Correct |
32 ms |
147548 KB |
Output is correct |
14 |
Correct |
33 ms |
147772 KB |
Output is correct |
15 |
Correct |
33 ms |
147556 KB |
Output is correct |
16 |
Correct |
34 ms |
147900 KB |
Output is correct |
17 |
Correct |
33 ms |
147800 KB |
Output is correct |
18 |
Correct |
35 ms |
147780 KB |
Output is correct |
19 |
Correct |
34 ms |
147800 KB |
Output is correct |
20 |
Correct |
34 ms |
147804 KB |
Output is correct |
21 |
Correct |
36 ms |
147804 KB |
Output is correct |
22 |
Correct |
35 ms |
147804 KB |
Output is correct |
23 |
Correct |
39 ms |
147764 KB |
Output is correct |
24 |
Correct |
34 ms |
147792 KB |
Output is correct |
25 |
Correct |
43 ms |
148380 KB |
Output is correct |
26 |
Correct |
43 ms |
148508 KB |
Output is correct |
27 |
Correct |
43 ms |
148316 KB |
Output is correct |
28 |
Correct |
38 ms |
148312 KB |
Output is correct |
29 |
Correct |
45 ms |
148560 KB |
Output is correct |
30 |
Correct |
47 ms |
148560 KB |
Output is correct |
31 |
Correct |
59 ms |
148676 KB |
Output is correct |
32 |
Correct |
55 ms |
148464 KB |
Output is correct |
33 |
Correct |
32 ms |
147536 KB |
Output is correct |
34 |
Correct |
33 ms |
147548 KB |
Output is correct |
35 |
Correct |
33 ms |
147804 KB |
Output is correct |
36 |
Correct |
32 ms |
147800 KB |
Output is correct |
37 |
Correct |
33 ms |
147540 KB |
Output is correct |
38 |
Correct |
209 ms |
161240 KB |
Output is correct |
39 |
Correct |
205 ms |
161240 KB |
Output is correct |
40 |
Correct |
265 ms |
161188 KB |
Output is correct |
41 |
Correct |
260 ms |
161240 KB |
Output is correct |
42 |
Correct |
361 ms |
156460 KB |
Output is correct |
43 |
Correct |
359 ms |
159748 KB |
Output is correct |
44 |
Correct |
358 ms |
160076 KB |
Output is correct |
45 |
Correct |
330 ms |
159584 KB |
Output is correct |
46 |
Correct |
72 ms |
155136 KB |
Output is correct |
47 |
Correct |
90 ms |
155600 KB |
Output is correct |
48 |
Correct |
202 ms |
158576 KB |
Output is correct |
49 |
Correct |
208 ms |
160560 KB |
Output is correct |
50 |
Correct |
117 ms |
154052 KB |
Output is correct |
51 |
Correct |
120 ms |
154192 KB |
Output is correct |
52 |
Correct |
1381 ms |
159068 KB |
Output is correct |
53 |
Correct |
421 ms |
160080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
147816 KB |
Output is correct |
2 |
Correct |
47 ms |
147800 KB |
Output is correct |
3 |
Correct |
46 ms |
147812 KB |
Output is correct |
4 |
Correct |
41 ms |
147536 KB |
Output is correct |
5 |
Correct |
42 ms |
147792 KB |
Output is correct |
6 |
Correct |
41 ms |
147800 KB |
Output is correct |
7 |
Correct |
43 ms |
147804 KB |
Output is correct |
8 |
Correct |
45 ms |
147812 KB |
Output is correct |
9 |
Correct |
44 ms |
147796 KB |
Output is correct |
10 |
Correct |
41 ms |
147800 KB |
Output is correct |
11 |
Correct |
42 ms |
147660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
147536 KB |
Output is correct |
2 |
Correct |
33 ms |
147548 KB |
Output is correct |
3 |
Correct |
33 ms |
147804 KB |
Output is correct |
4 |
Correct |
32 ms |
147800 KB |
Output is correct |
5 |
Correct |
33 ms |
147540 KB |
Output is correct |
6 |
Correct |
33 ms |
147540 KB |
Output is correct |
7 |
Correct |
270 ms |
186436 KB |
Output is correct |
8 |
Correct |
609 ms |
231628 KB |
Output is correct |
9 |
Correct |
565 ms |
232020 KB |
Output is correct |
10 |
Correct |
598 ms |
232180 KB |
Output is correct |
11 |
Correct |
86 ms |
183888 KB |
Output is correct |
12 |
Correct |
129 ms |
216628 KB |
Output is correct |
13 |
Correct |
139 ms |
221244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147792 KB |
Output is correct |
3 |
Correct |
33 ms |
147792 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
32 ms |
147804 KB |
Output is correct |
7 |
Correct |
33 ms |
147800 KB |
Output is correct |
8 |
Correct |
32 ms |
147804 KB |
Output is correct |
9 |
Correct |
34 ms |
147668 KB |
Output is correct |
10 |
Correct |
36 ms |
147644 KB |
Output is correct |
11 |
Correct |
33 ms |
147792 KB |
Output is correct |
12 |
Correct |
35 ms |
147804 KB |
Output is correct |
13 |
Correct |
32 ms |
147548 KB |
Output is correct |
14 |
Correct |
33 ms |
147772 KB |
Output is correct |
15 |
Correct |
33 ms |
147556 KB |
Output is correct |
16 |
Correct |
34 ms |
147900 KB |
Output is correct |
17 |
Correct |
33 ms |
147800 KB |
Output is correct |
18 |
Correct |
35 ms |
147780 KB |
Output is correct |
19 |
Correct |
34 ms |
147800 KB |
Output is correct |
20 |
Correct |
34 ms |
147804 KB |
Output is correct |
21 |
Correct |
36 ms |
147804 KB |
Output is correct |
22 |
Correct |
35 ms |
147804 KB |
Output is correct |
23 |
Correct |
39 ms |
147764 KB |
Output is correct |
24 |
Correct |
34 ms |
147792 KB |
Output is correct |
25 |
Correct |
43 ms |
148380 KB |
Output is correct |
26 |
Correct |
43 ms |
148508 KB |
Output is correct |
27 |
Correct |
43 ms |
148316 KB |
Output is correct |
28 |
Correct |
38 ms |
148312 KB |
Output is correct |
29 |
Correct |
45 ms |
148560 KB |
Output is correct |
30 |
Correct |
47 ms |
148560 KB |
Output is correct |
31 |
Correct |
59 ms |
148676 KB |
Output is correct |
32 |
Correct |
55 ms |
148464 KB |
Output is correct |
33 |
Correct |
209 ms |
161240 KB |
Output is correct |
34 |
Correct |
205 ms |
161240 KB |
Output is correct |
35 |
Correct |
265 ms |
161188 KB |
Output is correct |
36 |
Correct |
260 ms |
161240 KB |
Output is correct |
37 |
Correct |
361 ms |
156460 KB |
Output is correct |
38 |
Correct |
359 ms |
159748 KB |
Output is correct |
39 |
Correct |
358 ms |
160076 KB |
Output is correct |
40 |
Correct |
330 ms |
159584 KB |
Output is correct |
41 |
Correct |
72 ms |
155136 KB |
Output is correct |
42 |
Correct |
90 ms |
155600 KB |
Output is correct |
43 |
Correct |
202 ms |
158576 KB |
Output is correct |
44 |
Correct |
208 ms |
160560 KB |
Output is correct |
45 |
Correct |
117 ms |
154052 KB |
Output is correct |
46 |
Correct |
120 ms |
154192 KB |
Output is correct |
47 |
Correct |
1381 ms |
159068 KB |
Output is correct |
48 |
Correct |
421 ms |
160080 KB |
Output is correct |
49 |
Correct |
49 ms |
147816 KB |
Output is correct |
50 |
Correct |
47 ms |
147800 KB |
Output is correct |
51 |
Correct |
46 ms |
147812 KB |
Output is correct |
52 |
Correct |
41 ms |
147536 KB |
Output is correct |
53 |
Correct |
42 ms |
147792 KB |
Output is correct |
54 |
Correct |
41 ms |
147800 KB |
Output is correct |
55 |
Correct |
43 ms |
147804 KB |
Output is correct |
56 |
Correct |
45 ms |
147812 KB |
Output is correct |
57 |
Correct |
44 ms |
147796 KB |
Output is correct |
58 |
Correct |
41 ms |
147800 KB |
Output is correct |
59 |
Correct |
42 ms |
147660 KB |
Output is correct |
60 |
Correct |
33 ms |
147540 KB |
Output is correct |
61 |
Correct |
270 ms |
186436 KB |
Output is correct |
62 |
Correct |
609 ms |
231628 KB |
Output is correct |
63 |
Correct |
565 ms |
232020 KB |
Output is correct |
64 |
Correct |
598 ms |
232180 KB |
Output is correct |
65 |
Correct |
86 ms |
183888 KB |
Output is correct |
66 |
Correct |
129 ms |
216628 KB |
Output is correct |
67 |
Correct |
139 ms |
221244 KB |
Output is correct |
68 |
Correct |
32 ms |
147536 KB |
Output is correct |
69 |
Correct |
33 ms |
147548 KB |
Output is correct |
70 |
Correct |
33 ms |
147804 KB |
Output is correct |
71 |
Correct |
32 ms |
147800 KB |
Output is correct |
72 |
Correct |
33 ms |
147540 KB |
Output is correct |
73 |
Execution timed out |
5050 ms |
365964 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |