Submission #443077

# Submission time Handle Problem Language Result Execution time Memory
443077 2021-07-09T15:32:49 Z benedict0724 Fountain Parks (IOI21_parks) C++17
5 / 100
1173 ms 94660 KB
#include "parks.h"

#include <bits/stdc++.h>
using namespace std;

map<pair<int, int>, int> M, M2;
vector<int> adj[200000];
bool counting[200000];

vector<pair<int, int>> E;

int link[200002], CC = 0;

int _find(int x)
{
    if(x == link[x]) return x;
    return link[x] = _find(link[x]);
}

void _unite(int x, int y)
{
    x = _find(x); y = _find(y);
    if(x != y) CC++;
    link[x] = y;
}

int cnt = 0;
void count_fountains(int x)
{
    cnt++;
    counting[x] = true;
    for(int i : adj[x])
    {
        if(counting[i]) continue;
        count_fountains(i);
        E.push_back({x, i});
    }
}

int construct_roads(vector<int> x, vector<int> y) {

    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }

    int n = x.size();
    vector<int> u, v, a, b;

    int MAX = 0;
    for(int i=0;i<n;i++) MAX = max(MAX, x[i]);

    for(int i=0;i<n;i++)
        M[{x[i], y[i]}] = i+1;

    for(int i=0;i<n;i++)
    {
        if(M[{x[i]+2, y[i]}]) adj[i].push_back(M[{x[i]+2, y[i]}]-1);
        if(M[{x[i]-2, y[i]}]) adj[i].push_back(M[{x[i]-2, y[i]}]-1);
        if(M[{x[i], y[i]+2}]) adj[i].push_back(M[{x[i], y[i]+2}]-1);
        if(M[{x[i], y[i]-2}]) adj[i].push_back(M[{x[i], y[i]-2}]-1);
    }

    count_fountains(0);

    if(cnt < n) return 0;

    if(MAX <= 6)
    {
        for(int i=0;i<n;i++) link[i] = i;
        for(int i=0;i<n;i++)
        {
            for(int j : adj[i])
            {
                if(y[i] < y[j])
                {
                    u.push_back(i);
                    v.push_back(j);
                    b.push_back(y[i] + 1);
                    if(x[i] == 2 || (x[i] == 4 && y[i]%4 == 0))
                    {
                        a.push_back(x[i] - 1);
                        M2[{x[i]-1,y[i]+1}] = 1;
                    }

                    else
                    {
                        a.push_back(x[i] + 1);
                        M2[{x[i]+1, y[i]+1}] = 1;
                    }

                    _unite(i, j);
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j : adj[i])
            {
                if(_find(i) == _find(j)) continue;
                if(x[i] > x[j]) swap(i, j);
                u.push_back(i);
                v.push_back(j);
                a.push_back(x[i] + 1);
                if(M2[{x[i] + 1, y[i] + 1}]) b.push_back(y[i] - 1);
                else b.push_back(y[i] + 1);

                _unite(i, j);
            }
        }

        if(CC < n-1) return 2;
        build(u, v, a, b);
        return 1;
    }

    for(auto U : E)
    {
        int i = U.first, j = U.second;
        if(x[i] == x[j]) continue;
        if(x[i] > x[j]) swap(i, j);
        u.push_back(i);
        v.push_back(j);
        a.push_back(x[i]+1);
        if((x[i]+y[i])%4 == 0)
        {
            b.push_back(y[i]+1);
            M2[{x[i]+1, y[i]+1}] = 1;
        }
        else
        {
            b.push_back(y[i]-1);
            M2[{x[i]+1, y[i]-1}] = 1;
        }
    }

    for(auto U : E)
    {
        int i = U.first, j = U.second;
        if(x[i] != x[j]) continue;
        if(y[i] > y[j]) swap(i, j);
        u.push_back(i);
        v.push_back(j);
        b.push_back(y[i]+1);
        if(M2[{x[i]+1, y[i]+1}]) a.push_back(x[i]-1);
        else a.push_back(x[i]+1);
    }

    build(u, v, a, b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1173 ms 80772 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 6 ms 5324 KB Output is correct
26 Correct 8 ms 5580 KB Output is correct
27 Correct 9 ms 5708 KB Output is correct
28 Correct 329 ms 35848 KB Output is correct
29 Correct 561 ms 49160 KB Output is correct
30 Correct 841 ms 66252 KB Output is correct
31 Correct 1136 ms 79308 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4916 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 7 ms 5452 KB Output is correct
44 Correct 8 ms 5580 KB Output is correct
45 Incorrect 461 ms 37772 KB Wrong answer detected in grader
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1173 ms 80772 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 6 ms 5324 KB Output is correct
26 Correct 8 ms 5580 KB Output is correct
27 Correct 9 ms 5708 KB Output is correct
28 Correct 329 ms 35848 KB Output is correct
29 Correct 561 ms 49160 KB Output is correct
30 Correct 841 ms 66252 KB Output is correct
31 Correct 1136 ms 79308 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4916 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 7 ms 5452 KB Output is correct
44 Correct 8 ms 5580 KB Output is correct
45 Incorrect 461 ms 37772 KB Wrong answer detected in grader
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 890 ms 82276 KB Output is correct
21 Correct 882 ms 75924 KB Output is correct
22 Correct 901 ms 74392 KB Output is correct
23 Correct 759 ms 76668 KB Output is correct
24 Correct 829 ms 45764 KB Output is correct
25 Correct 790 ms 39828 KB Output is correct
26 Correct 808 ms 39748 KB Output is correct
27 Correct 960 ms 66264 KB Output is correct
28 Correct 985 ms 66188 KB Output is correct
29 Correct 1006 ms 66192 KB Output is correct
30 Correct 972 ms 66252 KB Output is correct
31 Correct 3 ms 4940 KB Output is correct
32 Correct 41 ms 9792 KB Output is correct
33 Correct 221 ms 25348 KB Output is correct
34 Correct 806 ms 79892 KB Output is correct
35 Correct 21 ms 6604 KB Output is correct
36 Correct 116 ms 12900 KB Output is correct
37 Correct 304 ms 20704 KB Output is correct
38 Correct 306 ms 27328 KB Output is correct
39 Correct 441 ms 35288 KB Output is correct
40 Correct 628 ms 45096 KB Output is correct
41 Correct 784 ms 52240 KB Output is correct
42 Correct 1047 ms 60508 KB Output is correct
43 Correct 3 ms 4940 KB Output is correct
44 Correct 3 ms 4940 KB Output is correct
45 Correct 3 ms 4940 KB Output is correct
46 Correct 3 ms 4996 KB Output is correct
47 Correct 3 ms 4940 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 4 ms 4940 KB Output is correct
51 Correct 3 ms 4940 KB Output is correct
52 Correct 4 ms 4940 KB Output is correct
53 Correct 3 ms 4940 KB Output is correct
54 Correct 7 ms 5452 KB Output is correct
55 Correct 8 ms 5540 KB Output is correct
56 Incorrect 410 ms 37680 KB Wrong answer detected in grader
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
17 Correct 959 ms 94660 KB Output is correct
18 Correct 942 ms 88508 KB Output is correct
19 Correct 882 ms 79252 KB Output is correct
20 Correct 876 ms 62576 KB Output is correct
21 Correct 871 ms 67800 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 91 ms 14248 KB Output is correct
24 Correct 43 ms 8424 KB Output is correct
25 Correct 185 ms 15540 KB Output is correct
26 Correct 394 ms 22852 KB Output is correct
27 Correct 392 ms 34968 KB Output is correct
28 Correct 521 ms 42324 KB Output is correct
29 Correct 694 ms 51048 KB Output is correct
30 Correct 812 ms 57680 KB Output is correct
31 Correct 1008 ms 65172 KB Output is correct
32 Incorrect 1029 ms 68792 KB Wrong answer detected in grader
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 446 ms 49264 KB Output is correct
10 Correct 24 ms 9540 KB Output is correct
11 Correct 127 ms 29080 KB Output is correct
12 Correct 35 ms 11720 KB Output is correct
13 Correct 74 ms 18116 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 476 ms 46048 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1173 ms 80772 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 6 ms 5324 KB Output is correct
26 Correct 8 ms 5580 KB Output is correct
27 Correct 9 ms 5708 KB Output is correct
28 Correct 329 ms 35848 KB Output is correct
29 Correct 561 ms 49160 KB Output is correct
30 Correct 841 ms 66252 KB Output is correct
31 Correct 1136 ms 79308 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4916 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 3 ms 4940 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 7 ms 5452 KB Output is correct
44 Correct 8 ms 5580 KB Output is correct
45 Incorrect 461 ms 37772 KB Wrong answer detected in grader
46 Halted 0 ms 0 KB -