Submission #797813

# Submission time Handle Problem Language Result Execution time Memory
797813 2023-07-30T00:18:52 Z Liudas Fountain Parks (IOI21_parks) C++17
30 / 100
1861 ms 119316 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
vector<vector<int>> new_tree;
void dfs(int head, vector<vector<int>>&tree, vector<int> &vis){
    vis[head] = true;
    for(int i : tree[head]){
        if(!vis[i]){
            new_tree[head].push_back(i);
            new_tree[i].push_back(head);
            dfs(i, tree, vis);
        }
    }
}
int count_benches(vector<int> &c, map<pair<int,int>, int> &taken){
    int s = 2;
    if(c[0] != c[2]){
        s -= taken[{c[0] - (c[0]-c[2])/2, c[1] + 1}];
        s -= taken[{c[0] - (c[0]-c[2])/2, c[1] - 1}];
    }
    else{
        s -= taken[{c[0] + 1, c[1] - (c[1] - c[3]) / 2}];
        s -= taken[{c[0] - 1, c[1] - (c[1] - c[3]) / 2}];
    }
    return s;
}
int construct_roads(vector<int> x, vector<int> y){
    int N = x.size();
    vector<vector<int>> tree(N);
    map<pair<int,int>, int> arr, bench, taken;
    map<array<int, 4>, bool> road;
    for(int i = 0; i < N; i ++){
        arr[{x[i], y[i]}] = i;
    }
    vector<int> dx = {-2, 2, 0, 0}, dy = {0,0,2,-2};
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < 4; j ++){
            if(arr.find({x[i] + dx[j], y[i] + dy[j]}) != arr.end()){
                tree[i].push_back(arr[{x[i] + dx[j], y[i] + dy[j]}]);
            }
        }
    }
    vector<int> vis(N, 0);
    new_tree.resize(N);
    dfs(0, tree, vis);
    tree = new_tree;
    for(int i = 0; i < N; i ++){
        for(int j : tree[i]){
            road[{x[i], y[i], x[j], y[j]}] = true;
            road[{x[j], y[j], x[i], y[i]}] = true;
            if(x[j] != x[i]){
                bench[{(x[i] + x[j])/2, y[i] + 1}] ++;
                bench[{(x[i] + x[j])/2, y[i] - 1}] ++;
            }
            if(y[j] != y[i]){
                bench[{x[i] + 1, (y[i] + y[j]) / 2}] ++;
                bench[{x[i] - 1, (y[i] + y[j]) / 2}] ++;
            }
        }
    }
    vector<pair<int, int>> pairs;
    //cout << road.size() << " " << bench.size() << endl;
    for(auto [l, r] : bench){
        pairs.push_back(l);
    }
    sort(pairs.begin(), pairs.end());
    for(int i : vis){
        if(!i){
            return 0;
        }
    }
    vector<int> ansu, ansv, ansa, ansb;
    for(auto[l ,r] : pairs){
        vector<int> dix = {-1, -1, 1, 1}, diy = {-1, 1, 1, -1};
        int bi = -1, bj = -1, s = 1e9;
        for(int i = 0; i < 4; i ++){
            for(int j = 0; j < 4; j ++){
                int ss = 1e9;
                if(road.find({l + dix[i], r + diy[i], l + dix[j], r + diy[j]}) != road.end()){
                    vector<int> tt = {l + dix[i], r + diy[i], l + dix[j], r + diy[j]};
                    ss = count_benches(tt, taken);
                }
                if(s > ss){
                    s = ss;
                    bi = i;
                    bj = j;
                }
            }
        }
        if(bi + 1){
            road.erase({l + dix[bi], r + diy[bi], l + dix[bj], r + diy[bj]});
            road.erase({l + dix[bj], r + diy[bj], l + dix[bi], r + diy[bi]});
            ansu.push_back(arr[{l + dix[bi], r + diy[bi]}]);
            ansv.push_back(arr[{l + dix[bj], r + diy[bj]}]);
            ansa.push_back(l);
            ansb.push_back(r);
            taken[{l, r}] = true;
        }
        
    }
    //cout << road.size() << endl;
    build(ansv, ansu, ansa, ansb);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1610 ms 103320 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 5 ms 880 KB Output is correct
26 Correct 5 ms 1108 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 512 ms 41416 KB Output is correct
29 Correct 864 ms 59756 KB Output is correct
30 Correct 1264 ms 81320 KB Output is correct
31 Correct 1622 ms 101856 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 224 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 280 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 852 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 686 ms 51588 KB Output is correct
46 Correct 1172 ms 75392 KB Output is correct
47 Correct 1119 ms 74992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1610 ms 103320 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 5 ms 880 KB Output is correct
26 Correct 5 ms 1108 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 512 ms 41416 KB Output is correct
29 Correct 864 ms 59756 KB Output is correct
30 Correct 1264 ms 81320 KB Output is correct
31 Correct 1622 ms 101856 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 224 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 280 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 852 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 686 ms 51588 KB Output is correct
46 Correct 1172 ms 75392 KB Output is correct
47 Correct 1119 ms 74992 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1721 ms 98992 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 7 ms 1108 KB Output is correct
58 Correct 28 ms 3284 KB Output is correct
59 Correct 14 ms 2640 KB Output is correct
60 Correct 693 ms 52000 KB Output is correct
61 Correct 1088 ms 69812 KB Output is correct
62 Correct 1317 ms 84276 KB Output is correct
63 Correct 1759 ms 100196 KB Output is correct
64 Correct 1 ms 304 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1609 ms 114788 KB Output is correct
68 Correct 1489 ms 115136 KB Output is correct
69 Correct 1540 ms 116280 KB Output is correct
70 Correct 8 ms 1620 KB Output is correct
71 Correct 11 ms 2204 KB Output is correct
72 Correct 684 ms 49816 KB Output is correct
73 Correct 1176 ms 77492 KB Output is correct
74 Correct 1747 ms 99560 KB Output is correct
75 Correct 1732 ms 107432 KB Output is correct
76 Correct 1532 ms 119316 KB Output is correct
77 Correct 8 ms 1848 KB Output is correct
78 Correct 14 ms 2872 KB Output is correct
79 Correct 710 ms 51372 KB Output is correct
80 Correct 1227 ms 77756 KB Output is correct
81 Correct 1760 ms 103532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1304 ms 103168 KB Output is correct
21 Correct 1314 ms 101720 KB Output is correct
22 Correct 1377 ms 98428 KB Output is correct
23 Correct 1253 ms 95708 KB Output is correct
24 Correct 258 ms 26060 KB Output is correct
25 Correct 377 ms 32468 KB Output is correct
26 Correct 339 ms 32568 KB Output is correct
27 Correct 1547 ms 102056 KB Output is correct
28 Correct 1553 ms 101952 KB Output is correct
29 Correct 1847 ms 102036 KB Output is correct
30 Correct 1861 ms 102080 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 75 ms 7128 KB Given structure is not connected: There is no path between vertices 0 and 1
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
17 Correct 1484 ms 117616 KB Output is correct
18 Correct 1484 ms 116148 KB Output is correct
19 Incorrect 1413 ms 103096 KB Given structure is not connected: There is no path between vertices 0 and 4025
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 619 ms 58304 KB Output is correct
10 Correct 39 ms 6092 KB Output is correct
11 Correct 266 ms 31816 KB Output is correct
12 Correct 60 ms 9016 KB Output is correct
13 Correct 76 ms 18948 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 645 ms 55160 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1610 ms 103320 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 5 ms 880 KB Output is correct
26 Correct 5 ms 1108 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 512 ms 41416 KB Output is correct
29 Correct 864 ms 59756 KB Output is correct
30 Correct 1264 ms 81320 KB Output is correct
31 Correct 1622 ms 101856 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 224 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 280 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 852 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 686 ms 51588 KB Output is correct
46 Correct 1172 ms 75392 KB Output is correct
47 Correct 1119 ms 74992 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1721 ms 98992 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 7 ms 1108 KB Output is correct
58 Correct 28 ms 3284 KB Output is correct
59 Correct 14 ms 2640 KB Output is correct
60 Correct 693 ms 52000 KB Output is correct
61 Correct 1088 ms 69812 KB Output is correct
62 Correct 1317 ms 84276 KB Output is correct
63 Correct 1759 ms 100196 KB Output is correct
64 Correct 1 ms 304 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1609 ms 114788 KB Output is correct
68 Correct 1489 ms 115136 KB Output is correct
69 Correct 1540 ms 116280 KB Output is correct
70 Correct 8 ms 1620 KB Output is correct
71 Correct 11 ms 2204 KB Output is correct
72 Correct 684 ms 49816 KB Output is correct
73 Correct 1176 ms 77492 KB Output is correct
74 Correct 1747 ms 99560 KB Output is correct
75 Correct 1732 ms 107432 KB Output is correct
76 Correct 1532 ms 119316 KB Output is correct
77 Correct 8 ms 1848 KB Output is correct
78 Correct 14 ms 2872 KB Output is correct
79 Correct 710 ms 51372 KB Output is correct
80 Correct 1227 ms 77756 KB Output is correct
81 Correct 1760 ms 103532 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 1304 ms 103168 KB Output is correct
86 Correct 1314 ms 101720 KB Output is correct
87 Correct 1377 ms 98428 KB Output is correct
88 Correct 1253 ms 95708 KB Output is correct
89 Correct 258 ms 26060 KB Output is correct
90 Correct 377 ms 32468 KB Output is correct
91 Correct 339 ms 32568 KB Output is correct
92 Correct 1547 ms 102056 KB Output is correct
93 Correct 1553 ms 101952 KB Output is correct
94 Correct 1847 ms 102036 KB Output is correct
95 Correct 1861 ms 102080 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 75 ms 7128 KB Given structure is not connected: There is no path between vertices 0 and 1
98 Halted 0 ms 0 KB -