QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#45450#1819. Cleaning RobotvexentoxWA 896ms101660kbC++142.1kb2022-08-23 22:13:052022-08-23 22:13:05

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 22:13:05]
  • 评测
  • 测评结果:WA
  • 用时:896ms
  • 内存:101660kb
  • [2022-08-23 22:13:05]
  • 提交

answer

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#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=5e6+5;
int n,m,k,fa[N];

int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}

void merge(int x,int y)
{
	x=find(x),y=find(y);
	if(x!=y) fa[x]=y;
}

int id(int i,int j)
{
	return m*(i-1)+j;
}

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}; 
 
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;
    _for(i,1,n*m) fa[i]=i;
    _for(i,1,n) _for(j,1,m) _for(p,0,3){
    	if(!g[i][j]) continue;
    	int nx=i+dx[p],ny=j+dy[p];
        if(nx<1 or nx>n or ny<1 or ny>m or !g[nx][ny]) continue;
        merge(id(i,j),id(nx,ny));
	}
	int root=-1;
	_for(i,1,n) _for(j,1,m){
		if(!g[i][j]) continue;
		int u=find(id(i,j));
		if(root==-1) root=u;
		else if(u!=root) 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3776kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 482ms
memory: 101560kb

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:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 813ms
memory: 101556kb

input:

2236 2236 2143
228 686
129 801
1105 382
2196 1919
2082 777
1672 268
174 916
234 491
1235 274
1645 1849
1114 1173
1351 1677
1294 1365
1059 197
611 1715
1769 1395
885 1902
1190 1304
1039 779
610 124
881 662
22 1664
239 1283
2218 2031
169 1417
291 143
228 1837
1518 2013
747 359
1997 1030
73 153
614 488...

output:

3

result:

ok answer is '3'

Test #4:

score: 0
Accepted
time: 444ms
memory: 101660kb

input:

2236 2236 63774
369 1861
1156 2150
1895 160
546 1944
1688 645
49 1888
430 973
1602 30
1988 971
1120 1307
322 1524
1559 1070
558 1147
973 1965
572 923
370 646
1436 1982
132 681
1410 308
1812 982
2191 2112
1311 396
1067 1330
659 477
873 881
1766 508
2091 1875
895 716
2058 1237
1374 1005
2183 1514
227 ...

output:

8

result:

ok answer is '8'

Test #5:

score: -100
Wrong Answer
time: 896ms
memory: 101660kb

input:

2236 2236 27245
1371 170
575 488
1594 575
1537 77
491 1580
1761 764
783 1265
242 923
893 71
1455 671
114 1289
1901 1481
1962 1160
861 2198
1055 89
2019 1481
1012 1415
1023 92
421 2018
1788 2006
1559 263
1387 1496
1556 479
166 1085
1368 2156
2076 2156
1028 617
919 146
698 1544
1730 2111
871 1478
768 ...

output:

20

result:

wrong answer expected '16', found '20'