Submission #1047806

# Submission time Handle Problem Language Result Execution time Memory
1047806 2024-08-07T16:05:23 Z vjudge1 Rectangles (IOI19_rect) C++17
23 / 100
434 ms 518696 KB
#include "rect.h"

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

const int lim=3000;

using pii=pair<int,int>;

vector<vector<int>>grid;

int n,m,l,r,x,y,cnt;
bool vis[lim][lim];

void dfs(int i,int j){
	if(vis[i][j])return;
	vis[i][j]=1;
	cnt++;
	l=min(l,i);
	r=max(r,i);
	x=min(x,j);
	y=max(y,j);
	if(i&&!grid[i-1][j])dfs(i-1,j);
	if(j&&!grid[i][j-1])dfs(i,j-1);
	if(i+1<n&&!grid[i+1][j])dfs(i+1,j);
	if(j+1<m&&!grid[i][j+1])dfs(i,j+1);
}

const int llim=100;

int mincol[llim][llim][llim],minrow[llim][llim][llim];

long long count_rectangles(std::vector<std::vector<int> > a) {
	grid=a;
	n=a.size();
	m=a[0].size();
	bool ok=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(a[i][j]!=1&&a[i][j]!=0){
				ok=0;
				goto outtt;
			}
		}
	}
	outtt:;
	if(n<3)return 0;
	if(n==3){
		vector<int>st;
		long int ans=0;
		for(int i=0;i<m;i++){
			if(1<st.size())
				for(int j=int(st.size())-2;0<=j;j--){
					if(a[1][st[j+1]]<a[1][i]){
						ans++;
					}else{
						break;
					}
				}
			while(st.size()&&a[1][st.back()]<a[1][i]){
				st.pop_back();
			}
			if(a[0][i]<=a[1][i]||a[2][i]<=a[1][i]){
				st.clear();
			}
			st.push_back(i);
		}
		return ans;
	}else if(ok){
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(a[i][j]==0&&!vis[i][j]){
					l=x=INT_MAX;
					r=y=0;
					cnt=0;
					dfs(i,j);
					if(l&&x&&r!=n-1&&y!=m-1&&cnt==(r-l+1)*(y-x+1)){
						ans++;
					}
				}
			}
		}
		return ans;
	}else{
		for(int i=0;i<n;i++){
			for(int l=0;l<m;l++){
				mincol[i][l][l]=a[i][l];
				for(int r=l+1;r<m;r++){
					mincol[i][l][r]=max(a[i][r],mincol[i][l][r-1]);
				}
			}
		}
		for(int i=0;i<m;i++){
			for(int l=0;l<n;l++){
				minrow[i][l][l]=a[l][i];
				for(int r=l+1;r<n;r++){
					mincol[i][l][r]=max(a[r][i],mincol[i][l][r-1]);
				}
			}
		}
		int ans=0;
		for(int l=0;l<n;l++){
			for(int r=l+2;r<n;r++){
				for(int x=0;x<m;x++){
					for(int y=x+2;y<m;y++){
						for(int i=l+1;i<r;i++){
							int mindude=minrow[i][x+1][y-1];
							if(a[i][x]<mindude||a[i][y]<mindude){
								goto nextcase;
							}
						}
						for(int i=x+1;i<y;i++){
							int mindude=mincol[i][l+1][r-1];
							if(a[l][i]<mindude||a[r][i]<mindude){
								goto nextcase;
							}
						}
						ans++;
						nextcase:;
					}
				}
			}
		}
		return ans;
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 80 ms 37728 KB Output is correct
3 Correct 155 ms 80940 KB Output is correct
4 Correct 153 ms 81236 KB Output is correct
5 Correct 153 ms 81236 KB Output is correct
6 Correct 179 ms 181328 KB Output is correct
7 Correct 373 ms 435876 KB Output is correct
8 Correct 434 ms 518696 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 2 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -