QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#45444 | #1819. Cleaning Robot | vexentox | RE | 2ms | 3948kb | C++14 | 1.8kb | 2022-08-23 21:30:18 | 2022-08-23 21:30:21 |
Judging History
answer
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<vector>
#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;
const int N=1e3+5;
int n,m,k;
int g[N][N],sumg[N][N],h[N][N],sumh[N][N];
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 dfs(int x,int y)
{
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;
dfs(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]){
dfs(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,1,n) _for(j,1,m) g[i][j]=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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3948kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: -100
Runtime Error
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...