Submission #623470

# Submission time Handle Problem Language Result Execution time Memory
623470 2022-08-05T16:25:54 Z cheissmart Fountain Parks (IOI21_parks) C++17
15 / 100
508 ms 133692 KB
#include "parks.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int dx[] = {0, 0, 2, -2}, dy[] = {2, -2, 0, 0};

int construct_roads(vi x, vi y) {
    int n = SZ(x);
    map<pi, int> mp;
    for(int i = 0; i < n; i++)
        mp[{x[i], y[i]}] = i;

    V<pi> edges;
    set<pi> vis;
    function<void(int, int)> dfs = [&] (int X, int Y) {
        vis.insert({X, Y});
        for(int i = 0; i < 4; i++) {
            int xx = X + dx[i], yy = Y + dy[i];
            if(mp.count({xx, yy}) && !vis.count({xx, yy})) {
                edges.EB(mp[{X, Y}], mp[{xx, yy}]);
                dfs(xx, yy);
            }
        }
    };
    dfs(x[0], y[0]);
    if(SZ(vis) != n) return 0;

    vi u, v, a(n - 1), b(n - 1);
    V<array<int, 3>> todo;
    set<pi> used;
    for(int i = 0; i < n - 1; i++) {
        u.PB(edges[i].F), v.PB(edges[i].S);
        int X = (x[edges[i].F] + x[edges[i].S]) / 2;
        int Y = (y[edges[i].F] + y[edges[i].S]) / 2;
        if(x[edges[i].F] == x[edges[i].S]) { // vertical
            if(X == 2) {
                X--;
            } else if(X == 6) {
                X++;
            } else {
                todo.PB({i, X, Y});
            }
        } else { // horizontal
            if(X == 3) {
                Y++;
            } else {
                assert(X == 5);
                Y--;
            }
        }
        a[i] = X, b[i] = Y;
        used.insert({X, Y});
    }
    for(auto[i, X, Y]:todo) {
        assert(!used.count({X - 1, Y}) || !used.count({X + 1, Y}));
        if(!used.count({X - 1, Y})) {
            X--;
        } else {
            X++;
        }
        a[i] = X, b[i] = Y;
    }
    build(u, v, a, b);
    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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 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 0 ms 212 KB Output is correct
23 Correct 508 ms 84448 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 176 ms 33928 KB Output is correct
29 Correct 279 ms 50776 KB Output is correct
30 Correct 379 ms 68028 KB Output is correct
31 Correct 497 ms 84460 KB Output is correct
32 Correct 1 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 239 ms 35032 KB Output is correct
46 Correct 306 ms 52908 KB Output is correct
47 Correct 328 ms 51668 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 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 0 ms 212 KB Output is correct
23 Correct 508 ms 84448 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 176 ms 33928 KB Output is correct
29 Correct 279 ms 50776 KB Output is correct
30 Correct 379 ms 68028 KB Output is correct
31 Correct 497 ms 84460 KB Output is correct
32 Correct 1 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 239 ms 35032 KB Output is correct
46 Correct 306 ms 52908 KB Output is correct
47 Correct 328 ms 51668 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Runtime error 1 ms 340 KB Execution killed with signal 6
51 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 KB Output is correct
17 Runtime error 399 ms 133692 KB Execution killed with signal 6
18 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 224 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 204 ms 40708 KB Output is correct
10 Correct 20 ms 4608 KB Output is correct
11 Correct 107 ms 22900 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11060 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 206 ms 33128 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 0 ms 212 KB Output is correct
23 Correct 508 ms 84448 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 176 ms 33928 KB Output is correct
29 Correct 279 ms 50776 KB Output is correct
30 Correct 379 ms 68028 KB Output is correct
31 Correct 497 ms 84460 KB Output is correct
32 Correct 1 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 239 ms 35032 KB Output is correct
46 Correct 306 ms 52908 KB Output is correct
47 Correct 328 ms 51668 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Runtime error 1 ms 340 KB Execution killed with signal 6
51 Halted 0 ms 0 KB -