Submission #797793

# Submission time Handle Problem Language Result Execution time Memory
797793 2023-07-29T22:45:22 Z Liudas Fountain Parks (IOI21_parks) C++17
15 / 100
3137 ms 115008 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
void dfs(int head, vector<vector<int>>&tree, vector<int> &vis){
    vis[head] = true;
    for(int i : tree[head]){
        if(!vis[i]){
            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]}]);
                road[{x[i], y[i], x[i]+dx[j], y[i] + dy[j]}] = true;
                road[{x[i]+dx[j], y[i] + dy[j], x[i], y[i]}] = true;
                if(dx[j]){
                    bench[{x[i] + dx[j]/2, y[i] + 1}] ++;
                    bench[{x[i] + dx[j]/2, y[i] - 1}] ++;
                }
                if(dy[j]){
                    bench[{x[i] + 1, y[i] + dy[j] / 2}] ++;
                    bench[{x[i] - 1, y[i] + dy[j] / 2}] ++;
                }
            }
        }
    }
    vector<pair<int, int>> pairs;
    for(auto [l, r] : bench){
        pairs.push_back(l);
    }
    sort(pairs.begin(), pairs.end(), [&](pair<int, int> a, pair<int, int> b){return bench[a] < bench[b];});
    vector<int> vis(N, 0);
    dfs(0, tree, vis);
    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;
        }
    }
    build(ansv, ansu, ansa, ansb);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 2994 ms 115008 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 12 ms 1640 KB Output is correct
27 Correct 16 ms 1972 KB Output is correct
28 Correct 1047 ms 44092 KB Output is correct
29 Correct 1598 ms 66380 KB Output is correct
30 Correct 2301 ms 89648 KB Output is correct
31 Correct 3091 ms 114080 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 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 212 KB Output is correct
41 Correct 0 ms 256 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 10 ms 1364 KB Output is correct
45 Correct 1026 ms 44160 KB Output is correct
46 Correct 1668 ms 64616 KB Output is correct
47 Correct 1677 ms 64208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 2994 ms 115008 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 12 ms 1640 KB Output is correct
27 Correct 16 ms 1972 KB Output is correct
28 Correct 1047 ms 44092 KB Output is correct
29 Correct 1598 ms 66380 KB Output is correct
30 Correct 2301 ms 89648 KB Output is correct
31 Correct 3091 ms 114080 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 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 212 KB Output is correct
41 Correct 0 ms 256 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 10 ms 1364 KB Output is correct
45 Correct 1026 ms 44160 KB Output is correct
46 Correct 1668 ms 64616 KB Output is correct
47 Correct 1677 ms 64208 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 1 ms 212 KB Output is correct
55 Correct 3137 ms 111464 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 12 ms 1312 KB Output is correct
58 Correct 46 ms 3476 KB Output is correct
59 Correct 47 ms 4796 KB Output is correct
60 Incorrect 1291 ms 55412 KB Given structure is not connected: There is no path between vertices 0 and 35744
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 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 1875 ms 86148 KB Output is correct
21 Correct 1970 ms 83824 KB Output is correct
22 Correct 1923 ms 83356 KB Output is correct
23 Correct 1969 ms 82992 KB Output is correct
24 Correct 272 ms 21492 KB Output is correct
25 Correct 2078 ms 81248 KB Output is correct
26 Correct 1833 ms 81228 KB Output is correct
27 Correct 2441 ms 91084 KB Output is correct
28 Correct 2411 ms 91048 KB Output is correct
29 Correct 2815 ms 91048 KB Output is correct
30 Correct 2808 ms 90976 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 99 ms 6208 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 KB Output is correct
17 Correct 2327 ms 100412 KB Output is correct
18 Correct 2397 ms 99484 KB Output is correct
19 Incorrect 2116 ms 85760 KB Given structure is not connected: There is no path between vertices 0 and 103320
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 264 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1026 ms 50000 KB Output is correct
10 Correct 60 ms 5276 KB Output is correct
11 Correct 464 ms 27104 KB Output is correct
12 Correct 97 ms 7716 KB Output is correct
13 Correct 246 ms 19472 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 7 ms 1140 KB Output is correct
16 Correct 1012 ms 48020 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 2994 ms 115008 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 7 ms 852 KB Output is correct
26 Correct 12 ms 1640 KB Output is correct
27 Correct 16 ms 1972 KB Output is correct
28 Correct 1047 ms 44092 KB Output is correct
29 Correct 1598 ms 66380 KB Output is correct
30 Correct 2301 ms 89648 KB Output is correct
31 Correct 3091 ms 114080 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 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 212 KB Output is correct
41 Correct 0 ms 256 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 10 ms 1364 KB Output is correct
45 Correct 1026 ms 44160 KB Output is correct
46 Correct 1668 ms 64616 KB Output is correct
47 Correct 1677 ms 64208 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 1 ms 212 KB Output is correct
55 Correct 3137 ms 111464 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 12 ms 1312 KB Output is correct
58 Correct 46 ms 3476 KB Output is correct
59 Correct 47 ms 4796 KB Output is correct
60 Incorrect 1291 ms 55412 KB Given structure is not connected: There is no path between vertices 0 and 35744
61 Halted 0 ms 0 KB -