답안 #623471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623471 2022-08-05T16:31:56 Z cheissmart 분수 공원 (IOI21_parks) C++17
30 / 100
512 ms 86124 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;
    V<array<int, 3>> todo2;
    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});
                continue;
            }
        } else { // horizontal
            if(X == 3) {
                Y++;
            } else {
                todo2.PB({i, X, Y});
                continue;
            }
        }
        a[i] = X, b[i] = Y;
        used.insert({X, Y});
    }
    for(auto[i, X, Y]:todo) {
        if(!used.count({X - 1, Y})) {
            X--;
        } else {
            X++;
        }
        a[i] = X, b[i] = Y;
        used.insert({X, Y});
    }
    for(auto[i, X, Y]:todo2) {
        assert(!used.count({X, Y + 1}) || !used.count({X + 1, Y}));
        if(!used.count({X, Y + 1})) {
            Y++;
        } else {
            Y--;
        }
        a[i] = X, b[i] = Y;
        used.insert({X, Y});
    }
    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 512 ms 84384 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 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 180 ms 33856 KB Output is correct
29 Correct 283 ms 50768 KB Output is correct
30 Correct 403 ms 69072 KB Output is correct
31 Correct 490 ms 84372 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 1 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 184 ms 35100 KB Output is correct
46 Correct 297 ms 52564 KB Output is correct
47 Correct 296 ms 51356 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 512 ms 84384 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 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 180 ms 33856 KB Output is correct
29 Correct 283 ms 50768 KB Output is correct
30 Correct 403 ms 69072 KB Output is correct
31 Correct 490 ms 84372 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 1 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 184 ms 35100 KB Output is correct
46 Correct 297 ms 52564 KB Output is correct
47 Correct 296 ms 51356 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 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 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 506 ms 76968 KB Output is correct
56 Correct 0 ms 304 KB Output is correct
57 Correct 3 ms 980 KB Output is correct
58 Correct 10 ms 2900 KB Output is correct
59 Correct 6 ms 1620 KB Output is correct
60 Correct 224 ms 42776 KB Output is correct
61 Correct 316 ms 57564 KB Output is correct
62 Correct 391 ms 64000 KB Output is correct
63 Correct 505 ms 82072 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 433 ms 75172 KB Output is correct
68 Correct 454 ms 75808 KB Output is correct
69 Correct 420 ms 79600 KB Output is correct
70 Correct 3 ms 852 KB Output is correct
71 Correct 5 ms 1236 KB Output is correct
72 Correct 202 ms 30844 KB Output is correct
73 Correct 319 ms 51056 KB Output is correct
74 Correct 451 ms 62348 KB Output is correct
75 Correct 496 ms 79040 KB Output is correct
76 Correct 432 ms 86124 KB Output is correct
77 Correct 4 ms 1108 KB Output is correct
78 Correct 7 ms 1588 KB Output is correct
79 Correct 204 ms 31944 KB Output is correct
80 Correct 324 ms 49208 KB Output is correct
81 Correct 448 ms 65700 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 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 Incorrect 484 ms 85880 KB Tree @(7, 199995) appears more than once: for edges on positions 199992 and 199993
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 KB Output is correct
17 Correct 502 ms 85396 KB Output is correct
18 Incorrect 451 ms 70448 KB Tree @(50001, 50001) appears more than once: for edges on positions 19663 and 119663
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
9 Correct 200 ms 40696 KB Output is correct
10 Correct 15 ms 4460 KB Output is correct
11 Correct 103 ms 22764 KB Output is correct
12 Correct 24 ms 6564 KB Output is correct
13 Correct 47 ms 11044 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 205 ms 33044 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 512 ms 84384 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 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 180 ms 33856 KB Output is correct
29 Correct 283 ms 50768 KB Output is correct
30 Correct 403 ms 69072 KB Output is correct
31 Correct 490 ms 84372 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 1 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 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 184 ms 35100 KB Output is correct
46 Correct 297 ms 52564 KB Output is correct
47 Correct 296 ms 51356 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 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 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 506 ms 76968 KB Output is correct
56 Correct 0 ms 304 KB Output is correct
57 Correct 3 ms 980 KB Output is correct
58 Correct 10 ms 2900 KB Output is correct
59 Correct 6 ms 1620 KB Output is correct
60 Correct 224 ms 42776 KB Output is correct
61 Correct 316 ms 57564 KB Output is correct
62 Correct 391 ms 64000 KB Output is correct
63 Correct 505 ms 82072 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 433 ms 75172 KB Output is correct
68 Correct 454 ms 75808 KB Output is correct
69 Correct 420 ms 79600 KB Output is correct
70 Correct 3 ms 852 KB Output is correct
71 Correct 5 ms 1236 KB Output is correct
72 Correct 202 ms 30844 KB Output is correct
73 Correct 319 ms 51056 KB Output is correct
74 Correct 451 ms 62348 KB Output is correct
75 Correct 496 ms 79040 KB Output is correct
76 Correct 432 ms 86124 KB Output is correct
77 Correct 4 ms 1108 KB Output is correct
78 Correct 7 ms 1588 KB Output is correct
79 Correct 204 ms 31944 KB Output is correct
80 Correct 324 ms 49208 KB Output is correct
81 Correct 448 ms 65700 KB Output is correct
82 Correct 0 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 Incorrect 484 ms 85880 KB Tree @(7, 199995) appears more than once: for edges on positions 199992 and 199993
86 Halted 0 ms 0 KB -