Submission #443015

# Submission time Handle Problem Language Result Execution time Memory
443015 2021-07-09T13:25:10 Z benedict0724 Fountain Parks (IOI21_parks) C++17
15 / 100
1075 ms 96624 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 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;
    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], y[i]+2}]) adj[i].push_back(M[{x[i], y[i]+2}]-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);
    }

    count_fountains(0);
    if(cnt < n) return 0;

    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]%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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4996 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 5000 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1059 ms 80576 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 5 ms 5324 KB Output is correct
26 Correct 10 ms 5520 KB Output is correct
27 Correct 9 ms 5652 KB Output is correct
28 Correct 307 ms 34928 KB Output is correct
29 Correct 522 ms 49288 KB Output is correct
30 Correct 774 ms 66648 KB Output is correct
31 Correct 1075 ms 80892 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 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 4 ms 4940 KB Output is correct
39 Correct 3 ms 4996 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4996 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 Correct 497 ms 42544 KB Output is correct
46 Correct 752 ms 60596 KB Output is correct
47 Correct 754 ms 60160 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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4996 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 5000 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1059 ms 80576 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 5 ms 5324 KB Output is correct
26 Correct 10 ms 5520 KB Output is correct
27 Correct 9 ms 5652 KB Output is correct
28 Correct 307 ms 34928 KB Output is correct
29 Correct 522 ms 49288 KB Output is correct
30 Correct 774 ms 66648 KB Output is correct
31 Correct 1075 ms 80892 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 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 4 ms 4940 KB Output is correct
39 Correct 3 ms 4996 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4996 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 Correct 497 ms 42544 KB Output is correct
46 Correct 752 ms 60596 KB Output is correct
47 Correct 754 ms 60160 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 4940 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Incorrect 3 ms 4940 KB Tree @(3, 5) appears more than once: for edges on positions 2 and 5
54 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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Incorrect 912 ms 81588 KB Tree @(3, 199999) appears more than once: for edges on positions 0 and 99999
21 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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 KB Output is correct
17 Correct 984 ms 96624 KB Output is correct
18 Correct 1026 ms 90716 KB Output is correct
19 Incorrect 920 ms 81544 KB Tree @(47609, 97609) appears more than once: for edges on positions 2 and 99998
20 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 4 ms 4992 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 455 ms 49656 KB Output is correct
10 Correct 24 ms 9544 KB Output is correct
11 Correct 126 ms 29324 KB Output is correct
12 Correct 36 ms 11756 KB Output is correct
13 Correct 79 ms 18496 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 6 ms 5452 KB Output is correct
16 Correct 398 ms 46568 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4996 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 5000 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 1059 ms 80576 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 5 ms 5324 KB Output is correct
26 Correct 10 ms 5520 KB Output is correct
27 Correct 9 ms 5652 KB Output is correct
28 Correct 307 ms 34928 KB Output is correct
29 Correct 522 ms 49288 KB Output is correct
30 Correct 774 ms 66648 KB Output is correct
31 Correct 1075 ms 80892 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 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 4 ms 4940 KB Output is correct
39 Correct 3 ms 4996 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 3 ms 4996 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 Correct 497 ms 42544 KB Output is correct
46 Correct 752 ms 60596 KB Output is correct
47 Correct 754 ms 60160 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 4940 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Incorrect 3 ms 4940 KB Tree @(3, 5) appears more than once: for edges on positions 2 and 5
54 Halted 0 ms 0 KB -