QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#45445#1819. Cleaning RobotvexentoxML 0ms3756kbC++142.0kb2022-08-23 21:37:072022-08-23 21:37:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-23 21:37:09]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3756kb
  • [2022-08-23 21:37:07]
  • 提交

answer

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue> 
#define _for(i,L,R) for(int i=L;i<=R;++i)
#define build(n,m,k) vector<vector<int>>(n+5,vector<int>(m+5,k))
//#define int long long

using namespace std;

using node=pair<int,int>;
#define x first
#define y second
int n,m,k;
vector<vector<int>> g,sumg,h,sumh;

void calc(int &x,int &y)
{
	x=max(1,x);y=max(1,y);
	x=min(x,n);y=min(y,m);
}

int getg(int x1,int y1,int x2,int y2)
{
	calc(x1,y1);calc(x2,y2);
	return sumg[x2][y2]-sumg[x1-1][y2]-sumg[x2][y1-1]+sumg[x1-1][y1-1];
}

int geth(int x1,int y1,int x2,int y2)
{
	calc(x1,y1);calc(x2,y2);
	return sumh[x2][y2]-sumh[x1-1][y2]-sumh[x2][y1-1]+sumh[x1-1][y1-1];
}

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

void bfs(int sx,int sy)
{
	queue<node> que;
	que.push({sx,sy});
	while(que.size()){
		int x=que.front().x,y=que.front().y;
		que.pop();
		h[x][y]=0;
		_for(i,0,3){
			int nx=x+dx[i],ny=y+dy[i];
			if(nx<1 or nx>n or ny<1 or ny>m or !h[nx][ny]) continue;
			que.push({nx,ny});
		}
	}
}


bool check(int mid)
{
	_for(i,1,n) _for(j,1,m){
		h[i][j]=getg(i-mid+1,j-mid+1,i,j)==mid*mid;
		sumh[i][j]=h[i][j]+sumh[i-1][j]+sumh[i][j-1]-sumh[i-1][j-1];
	}
	_for(i,1,n) _for(j,1,m) if(g[i][j] and !geth(i,j,i+mid-1,j+mid-1)) return 0;
	int ok=0;
	_for(i,1,n){
		_for(j,1,m) if(h[i][j]){
			bfs(i,j);
			ok=1;
			break;
		}
		if(ok) break;
	}
	_for(i,1,n) _for(j,1,m) if(h[i][j]) return 0;
	return 1;
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	g=build(n,m,1);
	_for(i,0,n) g[i][0]=0;
	_for(i,0,m) g[0][i]=0;
	sumg=h=sumh=build(n,m,0);
	while(k--){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x][y]=0;
	}
	_for(i,1,n) _for(j,1,m) sumg[i][j]=g[i][j]+sumg[i-1][j]+sumg[i][j-1]-sumg[i-1][j-1];
	int l=0,r=min(n,m)+1;
	while(l+1<r){
		int mid=l+r>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	if(l==0) l=-1;
	printf("%d\n",l);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Memory Limit Exceeded

input:

2236 2236 2214
28 1255
389 2175
730 592
1360 977
1225 752
1403 1798
1518 1381
147 745
659 249
951 1475
1826 1951
691 1033
81 1458
1487 1946
2106 1395
1995 629
470 891
1902 822
2210 2001
441 2130
1198 1539
2027 1101
215 1149
205 420
379 2104
308 1225
859 109
1417 2078
1764 376
1772 5
335 1113
917 118...

output:


result: