QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509164#1819. Cleaning RobothehuilangWA 647ms366864kbC++142.8kb2024-08-08 11:25:502024-08-08 11:25:50

Judging History

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

  • [2024-08-08 11:25:50]
  • 评测
  • 测评结果:WA
  • 用时:647ms
  • 内存:366864kb
  • [2024-08-08 11:25:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int vis[6000005],vis2[6000005];
int vis1[6000005];
int dont[6000005];
int id,T,n,m,k,a[6000006],b[6000005],cnt;
int v[]={0,0,1,-1},s[]={1,-1,0,0};
int l,r,mid,ans,w;
int pos(int x,int y)
{
    if(x==0||y==0) return 0;
    return (x-1)*m+y;
}
int qsum(int x,int y,int xx,int yy)
{
    return dont[pos(xx,yy)]-dont[pos(x-1,yy)]-dont[pos(xx,y-1)]+dont[pos(x-1,y-1)];
}
int qsum1(int x,int y,int xx,int yy)
{
    return vis1[pos(xx,yy)]-vis1[pos(x-1,yy)]-vis1[pos(xx,y-1)]+vis1[pos(x-1,y-1)];
}
void dfs(int x,int y)
{
    cnt++;vis[pos(x,y)]=1;
    for(int i=0;i<4;i++)
    {
        int q=x+v[i],p=y+s[i];
        if(q>=1&&q<=n&&p>=1&&p<=m&&vis[pos(q,p)]==0)
        dfs(q,p);
    }
}
void make_dont()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        dont[pos(i,j)]=dont[pos(i,j)]+dont[pos(i-1,j)]+dont[pos(i,j-1)]-dont[pos(i-1,j-1)];
    }
}
void make_vis1()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        vis1[pos(i,j)]=vis1[pos(i,j)]+vis1[pos(i-1,j)]+vis1[pos(i,j-1)]-vis1[pos(i-1,j-1)];
    }
}
bool check1()
{
    cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(vis[pos(i,j)]==0)
            {cnt=0;dfs(i,j);break;}
        }
        if(cnt!=0) break;
    }return cnt==(n*m-k);
}
void dfs2(int x,int y)
{
    w++;vis2[pos(x,y)]=1;
    for(int i=0;i<4;i++)
    {
        int q=x+v[i],p=y+s[i];
        if(q>=1&&q<=n&&p>=1&&p<=m&&qsum1(q,p,q,p)==1&&vis2[pos(q,p)]==0)
        dfs2(q,p);
    }
}
bool check(int x)
{
    for(int i=0;i<=3000000;i++) {vis1[i]=0;vis2[i]=0;}
    int fx=0,fy=0;cnt=0;
    for(int i=1;i+x-1<=n;i++)
    {
        for(int j=1;j+x-1<=m;j++)
        {
            if(qsum(i,j,i+x-1,j+x-1)==0)
            {    
                vis1[pos(i,j)]=1;cnt++;fx=i;fy=j;
            }
        }
    }
    if(cnt==0) return 0;
    make_vis1();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(qsum(i,j,i,j)==0&&qsum1(max(1,i-x+1),max(1,j-x+1),i,j)==0)
            return 0;
        }
    }
    w=0;dfs2(fx,fy);
    if(w==cnt) return 1;
    return 0;
}
void init()
{
    for(int i=0;i<=3000000;i++)
    {dont[i]=0;vis[i]=0;}
}
int main()
{
    // freopen("meet2.in","r",stdin);
    // freopen("meet.out","w",stdout);
   T=1;
    while(T--)
    {
        init();
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=k;i++) {scanf("%d%d",&a[i],&b[i]);dont[pos(a[i],b[i])]=1;vis[pos(a[i],b[i])]=1;}
        if(check1()==0) {printf("-1\n");continue;}
        make_dont();
        l=1;r=n;ans=-1;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(check(mid)) {ans=mid;l=mid+1;}
            else r=mid-1;
        }printf("%d\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 61104kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 606ms
memory: 353180kb

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: -100
Wrong Answer
time: 647ms
memory: 366864kb

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:

2

result:

wrong answer expected '3', found '2'