Submission #152344

#TimeUsernameProblemLanguageResultExecution timeMemory
152344arnold518문명 (KOI17_civilization)C++14
100 / 100
824 ms43068 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2000; const int INF = 2e9; const int dy[]={-1, 1, 0, 0}; const int dx[]={0, 0, -1, 1}; int N, K; int A[MAXN+10][MAXN+10]; bool vis[MAXN+10][MAXN+10]; int par[MAXN*MAXN+10]; int f(int y, int x) { y--; x--; return y*N+x; } int Find(int x) { return x==par[x]?x:(par[x]=Find(par[x])); } int main() { int i, j; scanf("%d%d", &N, &K); for(i=0; i<N*N; i++) par[i]=i; for(i=1; i<=N; i++) for(j=1; j<=N; j++) A[i][j]=INF; queue<pii> Q; for(i=1; i<=K; i++) { int y, x; scanf("%d%d", &y, &x); A[y][x]=0; Q.push({y, x}); } K=0; int ans=0; for(ans=0; ; ans++) { int sz=Q.size(); while(sz--) { pii now=Q.front(); Q.pop(); vis[now.first][now.second]=1; K++; for(i=0; i<4; i++) { pii nxt={now.first+dy[i], now.second+dx[i]}; if(!(1<=nxt.first && nxt.first<=N && 1<=nxt.second && nxt.second<=N)) continue; if(vis[nxt.first][nxt.second]) { int a=Find(f(now.first, now.second)), b=Find(f(nxt.first, nxt.second)); if(a!=b) K--; par[a]=b; } else if(A[nxt.first][nxt.second]==INF) { A[nxt.first][nxt.second]=A[now.first][now.second]+1; Q.push(nxt); } } } if(K==1) return !printf("%d", ans); } }

Compilation message (stderr)

civilization.cpp: In function 'int main()':
civilization.cpp:26: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:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &y, &x);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...