Submission #827784

# Submission time Handle Problem Language Result Execution time Memory
827784 2023-08-16T18:33:54 Z Baytoro Rectangles (IOI19_rect) C++17
50 / 100
5000 ms 548028 KB
#include "rect.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
const int N=2505;
int a[N][N],b[N],c[N],used[N][N];
int l,r,lx,rx,cnt,n,m;
void dfs(int x, int y){
	if(x==0 || y==0) return;
	if(x>n || y>m) return;
	if(a[x][y] || used[x][y]) return;
	used[x][y]=1;
	cnt++;
	l=min(l,x);
	r=max(r,x);
	lx=min(lx,y);
	rx=max(rx,y);
	if(!used[x+1][y]) dfs(x+1,y);
	if(!used[x-1][y]) dfs(x-1,y);
	if(!used[x][y+1]) dfs(x,y+1);
	if(!used[x][y-1]) dfs(x,y-1);
}
long long count_rectangles(vector<vector<int>> A) {
	n=A.size();
	m=A[0].size();
	if(min(n,m)<3) return 0;
	int mx=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			a[i+1][j+1]=A[i][j],mx=max(mx,A[i][j]);
	}
	int ans=0;
	if(mx<=1){
		for(int i=2;i<n;i++){
			for(int j=2;j<m;j++){
				if(used[i][j]) continue;
				l=1e9;
				r=0;
				lx=1e9;
				rx=0;
				cnt=0;
				dfs(i,j);
				if(l==1 || r==n) continue;
				if(lx==1 || rx==m) continue;
				if(cnt==(r-l+1)*(rx-lx+1))
					ans++;
			}
		}
	}
	else if(n<=3 || (n<=2500 && m<=2500)){
		for(int l=2;l<n;l++){
			for(int r=l;r<n;r++){
				for(int i=1;i<=m;i++){
					if(l==r) b[i]=a[l][i];
					else b[i]=max(b[i],a[r][i]);
				}
				for(int i=2;i<m;i++){
					for(int j=i;j<m;j++){
						if(b[j]>=min(a[l-1][j],a[r+1][j])) break;
						bool cnt=1;
						for(int k=l;k<=r;k++){
							if(i==j) c[k]=a[k][j];
							else c[k]=max(c[k],a[k][j]);
							if(c[k]>=min(a[k][i-1],a[k][j+1])){
								cnt=0;
							}
						}
						ans+=cnt;
					}
				}
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 260 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 260 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 16 ms 596 KB Output is correct
23 Correct 18 ms 716 KB Output is correct
24 Correct 17 ms 716 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 16 ms 596 KB Output is correct
18 Correct 18 ms 716 KB Output is correct
19 Correct 17 ms 716 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 260 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 676 ms 1580 KB Output is correct
31 Correct 687 ms 1580 KB Output is correct
32 Correct 663 ms 1584 KB Output is correct
33 Correct 15 ms 1492 KB Output is correct
34 Correct 16 ms 1580 KB Output is correct
35 Correct 16 ms 1572 KB Output is correct
36 Correct 22 ms 1492 KB Output is correct
37 Correct 17 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 16 ms 596 KB Output is correct
18 Correct 18 ms 716 KB Output is correct
19 Correct 17 ms 716 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 676 ms 1580 KB Output is correct
26 Correct 687 ms 1580 KB Output is correct
27 Correct 663 ms 1584 KB Output is correct
28 Correct 15 ms 1492 KB Output is correct
29 Correct 16 ms 1580 KB Output is correct
30 Correct 16 ms 1572 KB Output is correct
31 Correct 22 ms 1492 KB Output is correct
32 Correct 17 ms 1492 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 260 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 591 ms 8932 KB Output is correct
39 Correct 660 ms 8940 KB Output is correct
40 Correct 582 ms 8920 KB Output is correct
41 Correct 661 ms 8916 KB Output is correct
42 Execution timed out 5064 ms 8904 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 11 ms 412 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 260 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 103 ms 46884 KB Output is correct
8 Correct 223 ms 109956 KB Output is correct
9 Correct 228 ms 110600 KB Output is correct
10 Correct 223 ms 110620 KB Output is correct
11 Correct 178 ms 195604 KB Output is correct
12 Correct 413 ms 466204 KB Output is correct
13 Correct 463 ms 548028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 16 ms 596 KB Output is correct
18 Correct 18 ms 716 KB Output is correct
19 Correct 17 ms 716 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 676 ms 1580 KB Output is correct
26 Correct 687 ms 1580 KB Output is correct
27 Correct 663 ms 1584 KB Output is correct
28 Correct 15 ms 1492 KB Output is correct
29 Correct 16 ms 1580 KB Output is correct
30 Correct 16 ms 1572 KB Output is correct
31 Correct 22 ms 1492 KB Output is correct
32 Correct 17 ms 1492 KB Output is correct
33 Correct 591 ms 8932 KB Output is correct
34 Correct 660 ms 8940 KB Output is correct
35 Correct 582 ms 8920 KB Output is correct
36 Correct 661 ms 8916 KB Output is correct
37 Execution timed out 5064 ms 8904 KB Time limit exceeded
38 Halted 0 ms 0 KB -