#include "rect.h"
#include <vector>
#include <cmath>
#include <iostream>
#define sz(a) (a.size())
using namespace std;
int spr[705][11][705];
int spc[705][11][705];
int lg[705];
int query_r(int row, int l, int r){
int logo = lg[r-l+1];
return max(spr[row][logo][l],spr[row][logo][r-(1<<logo)+1]);
}
int query_c(int col, int l, int r){
int logo = lg[r-l+1];
return max(spc[col][logo][l],spc[col][logo][r-(1<<logo)+1]);
}
long long count_rectangles(vector<vector<int>> a) {
for (int i = 1; i < 705; ++i){
lg[i] = log2(i);
}
int n = sz(a);
int m = sz(a[0]);
int answer = 0;
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j){
spr[i][0][j] = a[i][j];
}
for (int k = 1; k < 11; ++k){
for (int j = 0; j < m-(1<<k)+1; ++j){
spr[i][k][j] = max(spr[i][k-1][j], spr[i][k-1][j+(1<<(k-1))]);
}
}
}
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
spc[i][0][j] = a[j][i];
}
for (int k = 1; k < 11; ++k){
for (int j = 0; j < n-(1<<k)+1; ++j){
spc[i][k][j] = max(spc[i][k-1][j], spc[i][k-1][j+(1<<(k-1))]);
}
}
}
for (int r1 = 1; r1 < n-1; ++r1){
for (int c1 = 1; c1 < m-1; ++c1){
for (int r2 = r1; r2 < n-1; ++r2){
if(a[r2][c1] >= a[r2][c1-1] ||
a[r2][c1] >= a[r1-1][c1]){
break;
}
bool milhem = false;
for (int c2 = c1; c2 < m-1 && !milhem; ++c2){
bool good = true;
for (int i = r1; i <= r2 && good; ++i){
int mx = query_r(i, c1, c2);
if(mx >= a[i][c1-1]){
good = false;
milhem = true;
}
if(mx >= a[i][c2+1]){
good = false;
}
}
for (int i = c1; i <= c2 && good; ++i){
int mx = query_c(i, r1, r2);
if(mx >= a[r1-1][i] || mx >= a[r2+1][i]){
good = false;
milhem = true;
}
}
if(good){
answer++;
}
}
}
}
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
1280 KB |
Output is correct |
11 |
Correct |
1 ms |
1280 KB |
Output is correct |
12 |
Correct |
1 ms |
1280 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
1280 KB |
Output is correct |
20 |
Correct |
1 ms |
896 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
1280 KB |
Output is correct |
11 |
Correct |
1 ms |
1280 KB |
Output is correct |
12 |
Correct |
1 ms |
1280 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
64 ms |
3712 KB |
Output is correct |
18 |
Correct |
63 ms |
3712 KB |
Output is correct |
19 |
Correct |
63 ms |
3712 KB |
Output is correct |
20 |
Correct |
3 ms |
3712 KB |
Output is correct |
21 |
Correct |
3 ms |
3712 KB |
Output is correct |
22 |
Correct |
3 ms |
3712 KB |
Output is correct |
23 |
Correct |
3 ms |
3712 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
1280 KB |
Output is correct |
28 |
Correct |
1 ms |
896 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
1280 KB |
Output is correct |
11 |
Correct |
1 ms |
1280 KB |
Output is correct |
12 |
Correct |
1 ms |
1280 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
64 ms |
3712 KB |
Output is correct |
18 |
Correct |
63 ms |
3712 KB |
Output is correct |
19 |
Correct |
63 ms |
3712 KB |
Output is correct |
20 |
Correct |
3 ms |
3712 KB |
Output is correct |
21 |
Correct |
3 ms |
3712 KB |
Output is correct |
22 |
Correct |
3 ms |
3712 KB |
Output is correct |
23 |
Correct |
3 ms |
3712 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2669 ms |
10488 KB |
Output is correct |
26 |
Correct |
2665 ms |
10488 KB |
Output is correct |
27 |
Correct |
2604 ms |
10488 KB |
Output is correct |
28 |
Correct |
8 ms |
10240 KB |
Output is correct |
29 |
Correct |
10 ms |
10240 KB |
Output is correct |
30 |
Correct |
11 ms |
10368 KB |
Output is correct |
31 |
Correct |
11 ms |
10368 KB |
Output is correct |
32 |
Correct |
11 ms |
10368 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
1280 KB |
Output is correct |
36 |
Correct |
1 ms |
896 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
1280 KB |
Output is correct |
11 |
Correct |
1 ms |
1280 KB |
Output is correct |
12 |
Correct |
1 ms |
1280 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
64 ms |
3712 KB |
Output is correct |
18 |
Correct |
63 ms |
3712 KB |
Output is correct |
19 |
Correct |
63 ms |
3712 KB |
Output is correct |
20 |
Correct |
3 ms |
3712 KB |
Output is correct |
21 |
Correct |
3 ms |
3712 KB |
Output is correct |
22 |
Correct |
3 ms |
3712 KB |
Output is correct |
23 |
Correct |
3 ms |
3712 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2669 ms |
10488 KB |
Output is correct |
26 |
Correct |
2665 ms |
10488 KB |
Output is correct |
27 |
Correct |
2604 ms |
10488 KB |
Output is correct |
28 |
Correct |
8 ms |
10240 KB |
Output is correct |
29 |
Correct |
10 ms |
10240 KB |
Output is correct |
30 |
Correct |
11 ms |
10368 KB |
Output is correct |
31 |
Correct |
11 ms |
10368 KB |
Output is correct |
32 |
Correct |
11 ms |
10368 KB |
Output is correct |
33 |
Correct |
52 ms |
48760 KB |
Output is correct |
34 |
Execution timed out |
5096 ms |
48736 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
33 ms |
20224 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Runtime error |
125 ms |
89336 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
2 ms |
1280 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1280 KB |
Output is correct |
10 |
Correct |
1 ms |
1280 KB |
Output is correct |
11 |
Correct |
1 ms |
1280 KB |
Output is correct |
12 |
Correct |
1 ms |
1280 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
64 ms |
3712 KB |
Output is correct |
18 |
Correct |
63 ms |
3712 KB |
Output is correct |
19 |
Correct |
63 ms |
3712 KB |
Output is correct |
20 |
Correct |
3 ms |
3712 KB |
Output is correct |
21 |
Correct |
3 ms |
3712 KB |
Output is correct |
22 |
Correct |
3 ms |
3712 KB |
Output is correct |
23 |
Correct |
3 ms |
3712 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2669 ms |
10488 KB |
Output is correct |
26 |
Correct |
2665 ms |
10488 KB |
Output is correct |
27 |
Correct |
2604 ms |
10488 KB |
Output is correct |
28 |
Correct |
8 ms |
10240 KB |
Output is correct |
29 |
Correct |
10 ms |
10240 KB |
Output is correct |
30 |
Correct |
11 ms |
10368 KB |
Output is correct |
31 |
Correct |
11 ms |
10368 KB |
Output is correct |
32 |
Correct |
11 ms |
10368 KB |
Output is correct |
33 |
Correct |
52 ms |
48760 KB |
Output is correct |
34 |
Execution timed out |
5096 ms |
48736 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |