#include "rect.h"
#include <bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define pii pair<int,int>
#define fi first
#define se second
#define rep(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
using namespace std;
const int moves[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
ll count_rectangles(vector<vector<int>> a) {
ll ans=0, n=a.size(), m=a[0].size();
if(max(n,m)>200 && (n>3)){
int x, y, z, b[4];
queue<int> q;
rep(i,0,n){
rep(j,0,m){
if(a[i][j]) continue;
q.push(i);
q.push(j);
z=0;
b[1]=0;
b[0]=1e9;
b[3]=0;
b[2]=1e9;
while(q.size()){
x=q.front();q.pop();
y=q.front();q.pop();
if(a[x][y]) continue;
a[x][y]=1;
if(!x || !y || x+1==n || y+1==m) z=-1e9;
b[1]=max(b[1],x);
b[0]=min(b[0],x);
b[3]=max(b[3],y);
b[2]=min(b[2],y);
z++;
rep(k,0,4){
x+=moves[k][0];
y+=moves[k][1];
if(0<=x && x<n && 0<=y && y<m && !a[x][y]){
q.push(x);
q.push(y);
}
x-=moves[k][0];
y-=moves[k][1];
}
}
if((b[1]-b[0]+1)*(b[3]-b[2]+1)==z) ans++;
}
}
return ans;
}
rep(ri,1,n-1){
rep(ci,1,m-1){
rep(rf,ri,n-1){
rep(cf,ci,m-1){
bool rect=1;
rep(i,ri,rf+1){
rep(j,ci,cf+1){
if(a[i][j]>=a[ri-1][j] || a[i][j]>=a[rf+1][j] || a[i][j]>=a[i][ci-1] || a[i][j]>=a[i][cf+1]){
rect=false;
break;
}
}
if(!rect) break;
}
ans+=rect;
}
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
33 ms |
348 KB |
Output is correct |
23 |
Correct |
35 ms |
604 KB |
Output is correct |
24 |
Correct |
33 ms |
348 KB |
Output is correct |
25 |
Correct |
21 ms |
348 KB |
Output is correct |
26 |
Correct |
24 ms |
344 KB |
Output is correct |
27 |
Correct |
23 ms |
500 KB |
Output is correct |
28 |
Correct |
24 ms |
348 KB |
Output is correct |
29 |
Correct |
11 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
33 ms |
348 KB |
Output is correct |
18 |
Correct |
35 ms |
604 KB |
Output is correct |
19 |
Correct |
33 ms |
348 KB |
Output is correct |
20 |
Correct |
21 ms |
348 KB |
Output is correct |
21 |
Correct |
24 ms |
344 KB |
Output is correct |
22 |
Correct |
23 ms |
500 KB |
Output is correct |
23 |
Correct |
24 ms |
348 KB |
Output is correct |
24 |
Correct |
11 ms |
484 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1321 ms |
960 KB |
Output is correct |
31 |
Correct |
1323 ms |
860 KB |
Output is correct |
32 |
Correct |
1359 ms |
1036 KB |
Output is correct |
33 |
Correct |
851 ms |
604 KB |
Output is correct |
34 |
Correct |
945 ms |
856 KB |
Output is correct |
35 |
Correct |
953 ms |
1036 KB |
Output is correct |
36 |
Correct |
962 ms |
856 KB |
Output is correct |
37 |
Correct |
901 ms |
1028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
33 ms |
348 KB |
Output is correct |
18 |
Correct |
35 ms |
604 KB |
Output is correct |
19 |
Correct |
33 ms |
348 KB |
Output is correct |
20 |
Correct |
21 ms |
348 KB |
Output is correct |
21 |
Correct |
24 ms |
344 KB |
Output is correct |
22 |
Correct |
23 ms |
500 KB |
Output is correct |
23 |
Correct |
24 ms |
348 KB |
Output is correct |
24 |
Correct |
11 ms |
484 KB |
Output is correct |
25 |
Correct |
1321 ms |
960 KB |
Output is correct |
26 |
Correct |
1323 ms |
860 KB |
Output is correct |
27 |
Correct |
1359 ms |
1036 KB |
Output is correct |
28 |
Correct |
851 ms |
604 KB |
Output is correct |
29 |
Correct |
945 ms |
856 KB |
Output is correct |
30 |
Correct |
953 ms |
1036 KB |
Output is correct |
31 |
Correct |
962 ms |
856 KB |
Output is correct |
32 |
Correct |
901 ms |
1028 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Incorrect |
16 ms |
7516 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
540 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
9 ms |
348 KB |
Output is correct |
7 |
Correct |
9 ms |
348 KB |
Output is correct |
8 |
Correct |
9 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
95 ms |
28500 KB |
Output is correct |
8 |
Correct |
203 ms |
61408 KB |
Output is correct |
9 |
Correct |
194 ms |
61564 KB |
Output is correct |
10 |
Correct |
196 ms |
61560 KB |
Output is correct |
11 |
Correct |
101 ms |
30544 KB |
Output is correct |
12 |
Correct |
183 ms |
57936 KB |
Output is correct |
13 |
Correct |
205 ms |
61704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
33 ms |
348 KB |
Output is correct |
18 |
Correct |
35 ms |
604 KB |
Output is correct |
19 |
Correct |
33 ms |
348 KB |
Output is correct |
20 |
Correct |
21 ms |
348 KB |
Output is correct |
21 |
Correct |
24 ms |
344 KB |
Output is correct |
22 |
Correct |
23 ms |
500 KB |
Output is correct |
23 |
Correct |
24 ms |
348 KB |
Output is correct |
24 |
Correct |
11 ms |
484 KB |
Output is correct |
25 |
Correct |
1321 ms |
960 KB |
Output is correct |
26 |
Correct |
1323 ms |
860 KB |
Output is correct |
27 |
Correct |
1359 ms |
1036 KB |
Output is correct |
28 |
Correct |
851 ms |
604 KB |
Output is correct |
29 |
Correct |
945 ms |
856 KB |
Output is correct |
30 |
Correct |
953 ms |
1036 KB |
Output is correct |
31 |
Correct |
962 ms |
856 KB |
Output is correct |
32 |
Correct |
901 ms |
1028 KB |
Output is correct |
33 |
Incorrect |
16 ms |
7516 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |