# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59109 | 2018-07-20T14:44:26 Z | andy627 | None (KOI17_civilization) | C++17 | 1000 ms | 55988 KB |
#include <stdio.h> #include <queue> #include <algorithm> #define INF 2e9 using namespace std; int par[2002*2002]; int dist[2002][2002],num[2002][2002]; bool is_gone[2002][2002]; 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(;;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); } } } if(cnt==1) break; } printf("%d\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1508 KB | Output is correct |
3 | Correct | 4 ms | 1584 KB | Output is correct |
4 | Correct | 3 ms | 1584 KB | Output is correct |
5 | Correct | 4 ms | 1620 KB | Output is correct |
6 | Correct | 5 ms | 1696 KB | Output is correct |
7 | Correct | 4 ms | 1744 KB | Output is correct |
8 | Correct | 4 ms | 1744 KB | Output is correct |
9 | Correct | 4 ms | 1744 KB | Output is correct |
10 | Correct | 3 ms | 1744 KB | Output is correct |
11 | Correct | 4 ms | 1744 KB | Output is correct |
12 | Correct | 5 ms | 1744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1508 KB | Output is correct |
3 | Correct | 4 ms | 1584 KB | Output is correct |
4 | Correct | 3 ms | 1584 KB | Output is correct |
5 | Correct | 4 ms | 1620 KB | Output is correct |
6 | Correct | 5 ms | 1696 KB | Output is correct |
7 | Correct | 4 ms | 1744 KB | Output is correct |
8 | Correct | 4 ms | 1744 KB | Output is correct |
9 | Correct | 4 ms | 1744 KB | Output is correct |
10 | Correct | 3 ms | 1744 KB | Output is correct |
11 | Correct | 4 ms | 1744 KB | Output is correct |
12 | Correct | 148 ms | 22204 KB | Output is correct |
13 | Correct | 103 ms | 22204 KB | Output is correct |
14 | Correct | 128 ms | 22204 KB | Output is correct |
15 | Correct | 96 ms | 22204 KB | Output is correct |
16 | Correct | 27 ms | 22204 KB | Output is correct |
17 | Correct | 462 ms | 25188 KB | Output is correct |
18 | Correct | 579 ms | 25188 KB | Output is correct |
19 | Correct | 551 ms | 25188 KB | Output is correct |
20 | Correct | 565 ms | 25316 KB | Output is correct |
21 | Correct | 522 ms | 25316 KB | Output is correct |
22 | Correct | 20 ms | 25316 KB | Output is correct |
23 | Correct | 58 ms | 25316 KB | Output is correct |
24 | Correct | 5 ms | 1744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1508 KB | Output is correct |
3 | Correct | 4 ms | 1584 KB | Output is correct |
4 | Correct | 3 ms | 1584 KB | Output is correct |
5 | Correct | 4 ms | 1620 KB | Output is correct |
6 | Correct | 5 ms | 1696 KB | Output is correct |
7 | Correct | 4 ms | 1744 KB | Output is correct |
8 | Correct | 4 ms | 1744 KB | Output is correct |
9 | Correct | 4 ms | 1744 KB | Output is correct |
10 | Correct | 3 ms | 1744 KB | Output is correct |
11 | Correct | 4 ms | 1744 KB | Output is correct |
12 | Correct | 148 ms | 22204 KB | Output is correct |
13 | Correct | 103 ms | 22204 KB | Output is correct |
14 | Correct | 128 ms | 22204 KB | Output is correct |
15 | Correct | 96 ms | 22204 KB | Output is correct |
16 | Correct | 27 ms | 22204 KB | Output is correct |
17 | Correct | 462 ms | 25188 KB | Output is correct |
18 | Correct | 579 ms | 25188 KB | Output is correct |
19 | Correct | 551 ms | 25188 KB | Output is correct |
20 | Correct | 565 ms | 25316 KB | Output is correct |
21 | Correct | 522 ms | 25316 KB | Output is correct |
22 | Correct | 20 ms | 25316 KB | Output is correct |
23 | Correct | 58 ms | 25316 KB | Output is correct |
24 | Correct | 360 ms | 51468 KB | Output is correct |
25 | Correct | 460 ms | 51564 KB | Output is correct |
26 | Correct | 303 ms | 51564 KB | Output is correct |
27 | Correct | 355 ms | 51568 KB | Output is correct |
28 | Correct | 251 ms | 51568 KB | Output is correct |
29 | Execution timed out | 1080 ms | 55988 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |