Submission #59107

# Submission time Handle Problem Language Result Execution time Memory
59107 2018-07-20T14:41:14 Z andy627 None (KOI17_civilization) C++17
0 / 100
4 ms 1400 KB
#include <stdio.h>
#include <queue>
#include <algorithm>
#define INF 2e9
using namespace std;

int par[2222*2222];
int dist[2222][2222],num[2222][2222];
bool is_gone[2222][2222];
queue<int> qx,qy;

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

int find_(int x){
    if(par[x]==x) return x;
    return par[x]=find_(par[x]);
}

int main(){
    int n,k;

    scanf("%d %d",&n,&k);

    int pos=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++) dist[i][j]=INF,num[i][j]=++pos;
    for(int i=1;i<=pos;i++) par[i]=i;

    for(int i=1;i<=k;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        dist[a][b]=0;
        qx.push(a); qy.push(b);
    }

    int ans=0,cnt=0;
    for(int cnt=0;cnt!=1;ans++){
        while(!qx.empty()){
            int px=qx.front(); qx.pop();
            int py=qy.front(); qy.pop();

            if(dist[px][py]!=ans){
                qx.push(px); qy.push(py);
                break;
            }

            is_gone[px][py]=1; cnt++;
            for(int d=0;d<4;d++){
                int nx=px+dx[d];
                int ny=py+dy[d];

                if(nx<1 || nx>n || ny<1 || ny>n) continue;
                if(is_gone[nx][ny]){
                    int root_a=find_(num[nx][ny]);
                    int root_b=find_(num[px][py]);

                    if(root_a!=root_b) cnt--;
                    par[root_b]=root_a;
                }
                else if(dist[nx][ny]==INF){
                    dist[nx][ny]=dist[px][py]+1;
                    qx.push(nx); qy.push(ny);
                }
            }
        }
    }

    printf("%d",ans);

    return 0;
}

Compilation message

civilization.cpp: In function 'int main()':
civilization.cpp:37:15: warning: unused variable 'cnt' [-Wunused-variable]
     int ans=0,cnt=0;
               ^~~
civilization.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
civilization.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -