#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <utility>
#include "rect.h"
using namespace std;
int n, m;
vector<vector<vector<bool> > > val, val2;
long long count_rectangles(vector<vector<int> > a) {
n = a.size(); m = a[0].size(); long long ans = 0;
val.push_back(vector<vector<bool> >()); val2.push_back(vector<vector<bool> >());
for (int r = 1; r < n-1; r++){
val.push_back(vector<vector<bool> >()); val[r].push_back(vector<bool>());
for (int cs = 1; cs < m-1; cs++){
val[r].push_back(vector<bool>()); int maxv = 0;
for (int t = 0; t < cs; t++){
val[r][cs].push_back(false);
}
for (int ce = cs; ce < m-1; ce++){
maxv = max(maxv, a[r][ce]);
if (maxv < a[r][cs-1] && maxv < a[r][ce+1]){
val[r][cs].push_back(true);
} else {
val[r][cs].push_back(false);
}
}
}
}
for (int c = 1; c < m-1; c++){
val2.push_back(vector<vector<bool> >()); val2[c].push_back(vector<bool>());
for (int rs = 1; rs < n-1; rs++){
val2[c].push_back(vector<bool>()); int maxv = 0;
for (int t = 0; t < rs; t++){
val2[c][rs].push_back(false);
}
for (int re = rs; re < n-1; re++){
maxv = max(maxv, a[re][c]);
if (maxv < a[rs-1][c] && maxv < a[re+1][c]){
val2[c][rs].push_back(true);
} else {
val2[c][rs].push_back(false);
}
}
}
}
for (int rs = 1; rs < n-1; rs++){
for (int cs = 1; cs < m-1; cs++){
for (int ce = cs; ce < m-1; ce++){
for (int re = rs; re < n-1; re++){
if (val[re][cs][ce]){
bool valid = true;
for (int i = cs; i <= ce; i++){
if (!val2[i][rs][re]){
valid = false;
}
}
if (valid){
ans++;
}
} else {
break;
}
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
22 ms |
1516 KB |
Output is correct |
18 |
Correct |
22 ms |
1644 KB |
Output is correct |
19 |
Correct |
22 ms |
1644 KB |
Output is correct |
20 |
Correct |
9 ms |
1516 KB |
Output is correct |
21 |
Correct |
11 ms |
1516 KB |
Output is correct |
22 |
Correct |
10 ms |
1540 KB |
Output is correct |
23 |
Correct |
10 ms |
1516 KB |
Output is correct |
24 |
Correct |
6 ms |
1004 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
22 ms |
1516 KB |
Output is correct |
18 |
Correct |
22 ms |
1644 KB |
Output is correct |
19 |
Correct |
22 ms |
1644 KB |
Output is correct |
20 |
Correct |
9 ms |
1516 KB |
Output is correct |
21 |
Correct |
11 ms |
1516 KB |
Output is correct |
22 |
Correct |
10 ms |
1540 KB |
Output is correct |
23 |
Correct |
10 ms |
1516 KB |
Output is correct |
24 |
Correct |
6 ms |
1004 KB |
Output is correct |
25 |
Correct |
890 ms |
8684 KB |
Output is correct |
26 |
Correct |
862 ms |
8684 KB |
Output is correct |
27 |
Correct |
895 ms |
8960 KB |
Output is correct |
28 |
Correct |
121 ms |
8428 KB |
Output is correct |
29 |
Correct |
123 ms |
8428 KB |
Output is correct |
30 |
Correct |
124 ms |
8684 KB |
Output is correct |
31 |
Correct |
130 ms |
8556 KB |
Output is correct |
32 |
Correct |
125 ms |
8556 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
22 ms |
1516 KB |
Output is correct |
18 |
Correct |
22 ms |
1644 KB |
Output is correct |
19 |
Correct |
22 ms |
1644 KB |
Output is correct |
20 |
Correct |
9 ms |
1516 KB |
Output is correct |
21 |
Correct |
11 ms |
1516 KB |
Output is correct |
22 |
Correct |
10 ms |
1540 KB |
Output is correct |
23 |
Correct |
10 ms |
1516 KB |
Output is correct |
24 |
Correct |
6 ms |
1004 KB |
Output is correct |
25 |
Correct |
890 ms |
8684 KB |
Output is correct |
26 |
Correct |
862 ms |
8684 KB |
Output is correct |
27 |
Correct |
895 ms |
8960 KB |
Output is correct |
28 |
Correct |
121 ms |
8428 KB |
Output is correct |
29 |
Correct |
123 ms |
8428 KB |
Output is correct |
30 |
Correct |
124 ms |
8684 KB |
Output is correct |
31 |
Correct |
130 ms |
8556 KB |
Output is correct |
32 |
Correct |
125 ms |
8556 KB |
Output is correct |
33 |
Correct |
4977 ms |
188972 KB |
Output is correct |
34 |
Correct |
4995 ms |
189096 KB |
Output is correct |
35 |
Correct |
4951 ms |
188908 KB |
Output is correct |
36 |
Correct |
4982 ms |
188908 KB |
Output is correct |
37 |
Execution timed out |
5075 ms |
189336 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
2156 KB |
Output is correct |
2 |
Correct |
39 ms |
1900 KB |
Output is correct |
3 |
Correct |
47 ms |
2172 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
45 ms |
2284 KB |
Output is correct |
6 |
Correct |
47 ms |
2284 KB |
Output is correct |
7 |
Correct |
47 ms |
2156 KB |
Output is correct |
8 |
Correct |
47 ms |
2156 KB |
Output is correct |
9 |
Correct |
47 ms |
2156 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Execution timed out |
5068 ms |
234628 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
22 ms |
1516 KB |
Output is correct |
18 |
Correct |
22 ms |
1644 KB |
Output is correct |
19 |
Correct |
22 ms |
1644 KB |
Output is correct |
20 |
Correct |
9 ms |
1516 KB |
Output is correct |
21 |
Correct |
11 ms |
1516 KB |
Output is correct |
22 |
Correct |
10 ms |
1540 KB |
Output is correct |
23 |
Correct |
10 ms |
1516 KB |
Output is correct |
24 |
Correct |
6 ms |
1004 KB |
Output is correct |
25 |
Correct |
890 ms |
8684 KB |
Output is correct |
26 |
Correct |
862 ms |
8684 KB |
Output is correct |
27 |
Correct |
895 ms |
8960 KB |
Output is correct |
28 |
Correct |
121 ms |
8428 KB |
Output is correct |
29 |
Correct |
123 ms |
8428 KB |
Output is correct |
30 |
Correct |
124 ms |
8684 KB |
Output is correct |
31 |
Correct |
130 ms |
8556 KB |
Output is correct |
32 |
Correct |
125 ms |
8556 KB |
Output is correct |
33 |
Correct |
4977 ms |
188972 KB |
Output is correct |
34 |
Correct |
4995 ms |
189096 KB |
Output is correct |
35 |
Correct |
4951 ms |
188908 KB |
Output is correct |
36 |
Correct |
4982 ms |
188908 KB |
Output is correct |
37 |
Execution timed out |
5075 ms |
189336 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |