Submission #604084

# Submission time Handle Problem Language Result Execution time Memory
604084 2022-07-24T17:20:06 Z StrawHatWess Rectangles (IOI19_rect) C++17
50 / 100
5000 ms 448572 KB
#include "rect.h"

#include <bits/stdc++.h>
using namespace std; 

typedef long long ll; 

typedef vector<int>vi; 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)

const int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};  

void ckmax(int &x, int y){x=max(x,y);}
void ckmin(int &x, int y){x=min(x,y);}

//-------------------

const int MX=2500+5; 

int N,M; 
vector<vi>a; 
int vis[MX][MX];

int n=0, mnx, mxx, mny, mxy; 

void dfs(int x, int y){
	ckmax(mxx,x); ckmax(mxy,y); 
	ckmin(mnx,x); ckmin(mny,y); 

	n++; 
	vis[x][y]=1; 
	FOR(m,0,4){
		int nx=x+dx[m], ny=y+dy[m]; 
		if(min(nx,ny)>=0 && nx<N && ny<M && !vis[nx][ny] && !a[nx][ny]) 
			dfs(nx,ny); 
	}
}


int sub6(){
	FOR(i,0,N) FOR(j,0,M) if(a[i][j]>1) return 0; 
	return 1;
}

ll count_rectangles(vector<vi> a) {
	N=sz(a); M=sz(a[0]); 
	::a=a; 

	memset(vis,0,sizeof(vis)); 

	if(sub6()){
		ll ans=0; 
		FOR(i,1,N-1) FOR(j,1,M-1) if(!a[i][j] && !vis[i][j]){
			n=0; 
			mnx=100000, mxx=-1, mny=100000, mxy=-1; 

			dfs(i,j); 

			if(n==(mxx-mnx+1)*(mxy-mny+1) && min(mnx,mny)>=1 && mxx<N-1 && mxy<M-1) ans++; 
		}
		return ans; 
	}

	ll ans=0;
	FOR(i,1,N-1) FOR(j,1,M-1){
		FOR(x,i,N-1) FOR(y,j,M-1){
			int f=1; 
			FOR(xx,i,x+1){
				FOR(yy,j,y+1){
					f&=(a[xx][yy]<min(min(a[xx][j-1],a[xx][y+1]),min(a[i-1][yy],a[x+1][yy]))); 
					if(!f) break; 
				}
				if(!f) break; 
			}
			ans+=f; 
		}



	}
	return ans; 
}

/*

6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 3 6
5 7 5 2 7
4 5 13 5 6


*/
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24788 KB Output is correct
2 Correct 14 ms 24828 KB Output is correct
3 Correct 14 ms 24748 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 13 ms 24812 KB Output is correct
6 Correct 13 ms 24788 KB Output is correct
7 Correct 10 ms 24788 KB Output is correct
8 Correct 11 ms 24788 KB Output is correct
9 Correct 13 ms 24852 KB Output is correct
10 Correct 12 ms 24788 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 11 ms 24788 KB Output is correct
13 Correct 10 ms 24788 KB Output is correct
14 Correct 10 ms 24852 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 10 ms 24776 KB Output is correct
17 Correct 10 ms 24788 KB Output is correct
18 Correct 10 ms 24792 KB Output is correct
19 Correct 10 ms 24808 KB Output is correct
20 Correct 10 ms 24788 KB Output is correct
21 Correct 11 ms 24740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24788 KB Output is correct
2 Correct 14 ms 24828 KB Output is correct
3 Correct 14 ms 24748 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 13 ms 24812 KB Output is correct
6 Correct 13 ms 24788 KB Output is correct
7 Correct 10 ms 24788 KB Output is correct
8 Correct 11 ms 24788 KB Output is correct
9 Correct 13 ms 24852 KB Output is correct
10 Correct 12 ms 24788 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 11 ms 24788 KB Output is correct
13 Correct 10 ms 24788 KB Output is correct
14 Correct 10 ms 24852 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 10 ms 24776 KB Output is correct
17 Correct 10 ms 24788 KB Output is correct
18 Correct 10 ms 24792 KB Output is correct
19 Correct 10 ms 24808 KB Output is correct
20 Correct 10 ms 24788 KB Output is correct
21 Correct 11 ms 24740 KB Output is correct
22 Correct 60 ms 24924 KB Output is correct
23 Correct 57 ms 24920 KB Output is correct
24 Correct 55 ms 24916 KB Output is correct
25 Correct 47 ms 24936 KB Output is correct
26 Correct 49 ms 24916 KB Output is correct
27 Correct 57 ms 24916 KB Output is correct
28 Correct 56 ms 24916 KB Output is correct
29 Correct 24 ms 24896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24788 KB Output is correct
2 Correct 14 ms 24828 KB Output is correct
3 Correct 14 ms 24748 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 13 ms 24812 KB Output is correct
6 Correct 13 ms 24788 KB Output is correct
7 Correct 10 ms 24788 KB Output is correct
8 Correct 11 ms 24788 KB Output is correct
9 Correct 13 ms 24852 KB Output is correct
10 Correct 12 ms 24788 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 11 ms 24788 KB Output is correct
13 Correct 10 ms 24788 KB Output is correct
14 Correct 10 ms 24852 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 10 ms 24776 KB Output is correct
17 Correct 60 ms 24924 KB Output is correct
18 Correct 57 ms 24920 KB Output is correct
19 Correct 55 ms 24916 KB Output is correct
20 Correct 47 ms 24936 KB Output is correct
21 Correct 49 ms 24916 KB Output is correct
22 Correct 57 ms 24916 KB Output is correct
23 Correct 56 ms 24916 KB Output is correct
24 Correct 24 ms 24896 KB Output is correct
25 Correct 10 ms 24788 KB Output is correct
26 Correct 10 ms 24792 KB Output is correct
27 Correct 10 ms 24808 KB Output is correct
28 Correct 10 ms 24788 KB Output is correct
29 Correct 11 ms 24740 KB Output is correct
30 Correct 1935 ms 25324 KB Output is correct
31 Correct 1836 ms 25324 KB Output is correct
32 Correct 1884 ms 25320 KB Output is correct
33 Correct 1535 ms 25328 KB Output is correct
34 Correct 1637 ms 25320 KB Output is correct
35 Correct 1623 ms 25324 KB Output is correct
36 Correct 1580 ms 25324 KB Output is correct
37 Correct 1539 ms 25316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24788 KB Output is correct
2 Correct 14 ms 24828 KB Output is correct
3 Correct 14 ms 24748 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 13 ms 24812 KB Output is correct
6 Correct 13 ms 24788 KB Output is correct
7 Correct 10 ms 24788 KB Output is correct
8 Correct 11 ms 24788 KB Output is correct
9 Correct 13 ms 24852 KB Output is correct
10 Correct 12 ms 24788 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 11 ms 24788 KB Output is correct
13 Correct 10 ms 24788 KB Output is correct
14 Correct 10 ms 24852 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 10 ms 24776 KB Output is correct
17 Correct 60 ms 24924 KB Output is correct
18 Correct 57 ms 24920 KB Output is correct
19 Correct 55 ms 24916 KB Output is correct
20 Correct 47 ms 24936 KB Output is correct
21 Correct 49 ms 24916 KB Output is correct
22 Correct 57 ms 24916 KB Output is correct
23 Correct 56 ms 24916 KB Output is correct
24 Correct 24 ms 24896 KB Output is correct
25 Correct 1935 ms 25324 KB Output is correct
26 Correct 1836 ms 25324 KB Output is correct
27 Correct 1884 ms 25320 KB Output is correct
28 Correct 1535 ms 25328 KB Output is correct
29 Correct 1637 ms 25320 KB Output is correct
30 Correct 1623 ms 25324 KB Output is correct
31 Correct 1580 ms 25324 KB Output is correct
32 Correct 1539 ms 25316 KB Output is correct
33 Correct 10 ms 24788 KB Output is correct
34 Correct 10 ms 24792 KB Output is correct
35 Correct 10 ms 24808 KB Output is correct
36 Correct 10 ms 24788 KB Output is correct
37 Correct 11 ms 24740 KB Output is correct
38 Execution timed out 5053 ms 30616 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24916 KB Output is correct
2 Correct 20 ms 24916 KB Output is correct
3 Correct 10 ms 25300 KB Output is correct
4 Correct 11 ms 24788 KB Output is correct
5 Correct 24 ms 24916 KB Output is correct
6 Correct 24 ms 24916 KB Output is correct
7 Correct 23 ms 24916 KB Output is correct
8 Correct 23 ms 24944 KB Output is correct
9 Correct 32 ms 24916 KB Output is correct
10 Correct 10 ms 24852 KB Output is correct
11 Correct 12 ms 24796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 24788 KB Output is correct
2 Correct 10 ms 24792 KB Output is correct
3 Correct 10 ms 24808 KB Output is correct
4 Correct 10 ms 24788 KB Output is correct
5 Correct 11 ms 24740 KB Output is correct
6 Correct 10 ms 24780 KB Output is correct
7 Correct 129 ms 58596 KB Output is correct
8 Correct 287 ms 98140 KB Output is correct
9 Correct 259 ms 98520 KB Output is correct
10 Correct 268 ms 98524 KB Output is correct
11 Correct 201 ms 173904 KB Output is correct
12 Correct 386 ms 381456 KB Output is correct
13 Correct 407 ms 448572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24788 KB Output is correct
2 Correct 14 ms 24828 KB Output is correct
3 Correct 14 ms 24748 KB Output is correct
4 Correct 13 ms 24788 KB Output is correct
5 Correct 13 ms 24812 KB Output is correct
6 Correct 13 ms 24788 KB Output is correct
7 Correct 10 ms 24788 KB Output is correct
8 Correct 11 ms 24788 KB Output is correct
9 Correct 13 ms 24852 KB Output is correct
10 Correct 12 ms 24788 KB Output is correct
11 Correct 11 ms 24788 KB Output is correct
12 Correct 11 ms 24788 KB Output is correct
13 Correct 10 ms 24788 KB Output is correct
14 Correct 10 ms 24852 KB Output is correct
15 Correct 10 ms 24788 KB Output is correct
16 Correct 10 ms 24776 KB Output is correct
17 Correct 60 ms 24924 KB Output is correct
18 Correct 57 ms 24920 KB Output is correct
19 Correct 55 ms 24916 KB Output is correct
20 Correct 47 ms 24936 KB Output is correct
21 Correct 49 ms 24916 KB Output is correct
22 Correct 57 ms 24916 KB Output is correct
23 Correct 56 ms 24916 KB Output is correct
24 Correct 24 ms 24896 KB Output is correct
25 Correct 1935 ms 25324 KB Output is correct
26 Correct 1836 ms 25324 KB Output is correct
27 Correct 1884 ms 25320 KB Output is correct
28 Correct 1535 ms 25328 KB Output is correct
29 Correct 1637 ms 25320 KB Output is correct
30 Correct 1623 ms 25324 KB Output is correct
31 Correct 1580 ms 25324 KB Output is correct
32 Correct 1539 ms 25316 KB Output is correct
33 Execution timed out 5053 ms 30616 KB Time limit exceeded
34 Halted 0 ms 0 KB -