Submission #152344

# Submission time Handle Problem Language Result Execution time Memory
152344 2019-09-07T16:21:29 Z arnold518 None (KOI17_civilization) C++14
100 / 100
824 ms 43068 KB
#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

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 time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 988 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 988 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 68 ms 14052 KB Output is correct
13 Correct 54 ms 14148 KB Output is correct
14 Correct 72 ms 14204 KB Output is correct
15 Correct 50 ms 14072 KB Output is correct
16 Correct 18 ms 12792 KB Output is correct
17 Correct 191 ms 17784 KB Output is correct
18 Correct 216 ms 17852 KB Output is correct
19 Correct 206 ms 17764 KB Output is correct
20 Correct 209 ms 17948 KB Output is correct
21 Correct 207 ms 17784 KB Output is correct
22 Correct 12 ms 12152 KB Output is correct
23 Correct 51 ms 14076 KB Output is correct
24 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 988 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 68 ms 14052 KB Output is correct
13 Correct 54 ms 14148 KB Output is correct
14 Correct 72 ms 14204 KB Output is correct
15 Correct 50 ms 14072 KB Output is correct
16 Correct 18 ms 12792 KB Output is correct
17 Correct 191 ms 17784 KB Output is correct
18 Correct 216 ms 17852 KB Output is correct
19 Correct 206 ms 17764 KB Output is correct
20 Correct 209 ms 17948 KB Output is correct
21 Correct 207 ms 17784 KB Output is correct
22 Correct 12 ms 12152 KB Output is correct
23 Correct 51 ms 14076 KB Output is correct
24 Correct 191 ms 35732 KB Output is correct
25 Correct 249 ms 35728 KB Output is correct
26 Correct 174 ms 34924 KB Output is correct
27 Correct 199 ms 35704 KB Output is correct
28 Correct 134 ms 34424 KB Output is correct
29 Correct 751 ms 40568 KB Output is correct
30 Correct 659 ms 37752 KB Output is correct
31 Correct 824 ms 43008 KB Output is correct
32 Correct 806 ms 42880 KB Output is correct
33 Correct 811 ms 43068 KB Output is correct
34 Correct 190 ms 35832 KB Output is correct
35 Correct 29 ms 31736 KB Output is correct
36 Correct 3 ms 1016 KB Output is correct