## Submission #204462

# Submission time Handle Problem Language Result Execution time Memory
204462 2020-02-25T19:55:51 Z 14kg None (KOI17_civilization) C++11
54 / 100
1000 ms 39992 KB
```#include <stdio.h>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>
#define max2(x,y) (x>y?x:y)

using namespace std;
typedef pair<int,pair<int,int> > pip;
int n, m, p[100001], max_t;
int dy[4]={1,-1,0,0}, dx[4]={0,0,1,-1};
pair<int,int> board[2001][2001];
queue<int> Q;
priority_queue<pip,vector<pip>,greater<pip> > Q2;

int get_p(int x){
if(p[x]==x) return x;
return p[x]=get_p(p[x]);
}
int main(){
int x, y, xx, yy, tx, ty;

scanf("%d %d",&n,&m);
for(int i=1; i<=m; i++){
scanf("%d %d",&x,&y);
board[x][y]={i,0}, p[i]=i;
Q.push(x), Q.push(y);
}

while(!Q.empty()){
xx=Q.front(), Q.pop();
yy=Q.front(), Q.pop();

while(Q2.empty()==false && Q2.top().first<=board[xx][yy].second){
int px=get_p(Q2.top().second.first);
int py=get_p(Q2.top().second.second);
if(px!=py) p[px]=py, max_t=max2(max_t,Q2.top().first);
Q2.pop();
}

for(int i=0; i<4; i++){
tx=xx+dx[i], ty=yy+dy[i];
if(1<=tx && tx<=n && 1<=ty && ty<=n){
if(board[tx][ty].first==0){
board[tx][ty]={board[xx][yy].first,board[xx][yy].second+1};
Q.push(tx), Q.push(ty);
}

int px=get_p(board[tx][ty].first);
int py=get_p(board[xx][yy].first);
if(px!=py) Q2.push({board[tx][ty].second,{px,py}});
}
}
}
while(!Q2.empty()){
int px=get_p(Q2.top().second.first);
int py=get_p(Q2.top().second.second);
if(px!=py) p[px]=py, max_t=max2(max_t,Q2.top().first);
Q2.pop();
} printf("%d",max_t);
}
```

### Compilation message

```civilization.cpp: In function 'int main()':
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,&m);
~~~~~^~~~~~~~~~~~~~~
civilization.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
~~~~~^~~~~~~~~~~~~~~```

#### Subtask #1 19.0 / 19.0

# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 6 ms 760 KB Output is correct

#### Subtask #2 35.0 / 35.0

# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 74 ms 12152 KB Output is correct
13 Correct 69 ms 12152 KB Output is correct
14 Correct 58 ms 12280 KB Output is correct
15 Correct 69 ms 12128 KB Output is correct
16 Correct 68 ms 12152 KB Output is correct
17 Correct 309 ms 17712 KB Output is correct
18 Correct 305 ms 17712 KB Output is correct
19 Correct 308 ms 17712 KB Output is correct
20 Correct 310 ms 17744 KB Output is correct
21 Correct 309 ms 17840 KB Output is correct
22 Correct 78 ms 12152 KB Output is correct
23 Correct 79 ms 12152 KB Output is correct
24 Correct 6 ms 760 KB Output is correct

#### Subtask #3 0 / 46.0

# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 7 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 74 ms 12152 KB Output is correct
13 Correct 69 ms 12152 KB Output is correct
14 Correct 58 ms 12280 KB Output is correct
15 Correct 69 ms 12128 KB Output is correct
16 Correct 68 ms 12152 KB Output is correct
17 Correct 309 ms 17712 KB Output is correct
18 Correct 305 ms 17712 KB Output is correct
19 Correct 308 ms 17712 KB Output is correct
20 Correct 310 ms 17744 KB Output is correct
21 Correct 309 ms 17840 KB Output is correct
22 Correct 78 ms 12152 KB Output is correct
23 Correct 79 ms 12152 KB Output is correct
24 Correct 275 ms 31736 KB Output is correct
25 Correct 317 ms 31736 KB Output is correct
26 Correct 286 ms 31736 KB Output is correct
27 Correct 330 ms 31740 KB Output is correct
28 Correct 307 ms 31736 KB Output is correct
29 Correct 872 ms 37116 KB Output is correct
30 Correct 729 ms 33996 KB Output is correct
31 Execution timed out 1004 ms 39992 KB Time limit exceeded
32 Halted 0 ms 0 KB -