Submission #85978

# Submission time Handle Problem Language Result Execution time Memory
85978 2018-11-23T16:11:47 Z tjdgus4384 None (KOI17_civilization) C++14
54 / 100
1000 ms 48660 KB
#include<cstdio>
#include<string.h>
#include<queue>
using namespace std;
queue<pair<pair<int, int>, pair<int, int> > > q;
int pa[100001], sz[100001], ar[2001][2001];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int find(int u)
{
    if(pa[u] == u) return u;
    return pa[u] = find(pa[u]);
}

void merge(int u, int v)
{
    u = find(u); v = find(v);
    if(u == v) return;
    sz[u] += sz[v];
    pa[v] = u;
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1;i <= k;i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        q.push({{x, y}, {i, 0}});
        pa[i] = i;
        sz[i] = 1;
    }
    while(!q.empty())
    {
        int x = q.front().first.first;
        int y = q.front().first.second;
        int s = q.front().second.first;
        int t = q.front().second.second;
        q.pop();
        if(ar[x][y] == 0)
        {
            ar[x][y] = s;
            for(int i = 0;i < 4;i++)
            {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
                if(ar[nx][ny] == 0) q.push({{nx, ny}, {s, t + 1}});
                else merge(ar[nx][ny], s);
            }
        }
        else
        {
            merge(ar[x][y], s);
        }
        if(sz[find(1)] == k)
        {
            printf("%d", t);
            return 0;
        }
    }
}

Compilation message

civilization.cpp: In function 'int main()':
civilization.cpp:27: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:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 3 ms 928 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 2 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 3 ms 928 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 2 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 68 ms 8336 KB Output is correct
13 Correct 48 ms 8336 KB Output is correct
14 Correct 59 ms 8336 KB Output is correct
15 Correct 41 ms 8336 KB Output is correct
16 Correct 9 ms 8336 KB Output is correct
17 Correct 233 ms 22752 KB Output is correct
18 Correct 229 ms 23588 KB Output is correct
19 Correct 228 ms 24332 KB Output is correct
20 Correct 279 ms 25088 KB Output is correct
21 Correct 265 ms 25812 KB Output is correct
22 Correct 4 ms 25812 KB Output is correct
23 Correct 65 ms 25812 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 3 ms 928 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 2 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 68 ms 8336 KB Output is correct
13 Correct 48 ms 8336 KB Output is correct
14 Correct 59 ms 8336 KB Output is correct
15 Correct 41 ms 8336 KB Output is correct
16 Correct 9 ms 8336 KB Output is correct
17 Correct 233 ms 22752 KB Output is correct
18 Correct 229 ms 23588 KB Output is correct
19 Correct 228 ms 24332 KB Output is correct
20 Correct 279 ms 25088 KB Output is correct
21 Correct 265 ms 25812 KB Output is correct
22 Correct 4 ms 25812 KB Output is correct
23 Correct 65 ms 25812 KB Output is correct
24 Correct 170 ms 25812 KB Output is correct
25 Correct 237 ms 25812 KB Output is correct
26 Correct 141 ms 25812 KB Output is correct
27 Correct 208 ms 25812 KB Output is correct
28 Correct 116 ms 25812 KB Output is correct
29 Correct 858 ms 39144 KB Output is correct
30 Correct 723 ms 39144 KB Output is correct
31 Correct 997 ms 47856 KB Output is correct
32 Execution timed out 1008 ms 48660 KB Time limit exceeded
33 Halted 0 ms 0 KB -