답안 #599986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599986 2022-07-20T11:11:12 Z Valaki2 분수 공원 (IOI21_parks) C++17
30 / 100
533 ms 55428 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

#define x X
#define y Y

#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 2e5;
const vector<pii > directions = {mp(-2, 0), mp(0, -2), mp(0, 2), mp(2, 0)};

bool check_possibility(int n, vector<int> x, vector<int> y) {
    unordered_map<int, unordered_map<int, bool> > m;
    unordered_map<int, unordered_map<int, int> > f;
    for(int i = 0; i < n; i++) {
        f[x[i]][y[i]] = i + 1;
    }
    queue<int> q;
    q.push(0);
    m[x[0]][y[0]] = true;
    int cnt = 0;
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        cnt++;
        for(pii dir : directions) {
            pii new_point = mp(x[cur] + dir.fi, y[cur] + dir.se);
            if(f[new_point.fi][new_point.se] && !m[new_point.fi][new_point.se]) {
                m[new_point.fi][new_point.se] = true;
                int new_id = f[new_point.fi][new_point.se] - 1;
                q.push(new_id);
            }
        }
    }
    return (cnt == n);
}

struct fountain {
    int x, y, id;
    fountain() : x(0), y(0), id(-1) {}
    fountain(int x_, int y_, int id_) :
        x(x_), y(y_), id(id_) {}
};

int n;
vector<fountain > points;
vector<int> x;
vector<int> y;
unordered_map<int, unordered_map<int, int> > fountain_at;

unordered_map<int, unordered_map<int, bool> > bench_at;
vector<int> ans_u;
vector<int> ans_v;
vector<int> ans_a;
vector<int> ans_b;

void build_road_bench(int road_u, int road_v, pii bench_pos) {
    ans_u.pb(road_u);
    ans_v.pb(road_v);
    ans_a.pb(bench_pos.fi);
    ans_b.pb(bench_pos.se);
    bench_at[bench_pos.fi][bench_pos.se] = true;
}

vector<fountain> by_a;
vector<fountain> by_b;
vector<fountain> by_c;

bool sort_by_y(const fountain &a, const fountain &b) {
    return a.y < b.y;
}

void solve() {
    /*for(fountain p : points) {
        if(p.x == 2) {
            by_a.pb(p);
        }
        if(p.x == 4) {
            by_b.pb(p);
        }
        if(p.x == 6) {
            by_c.pb(p);
        }
    }
    sort(by_a.begin(), by_a.end(), sort_by_y);
    sort(by_b.begin(), by_b.end(), sort_by_y);
    sort(by_c.begin(), by_c.end(), sort_by_y);*/
    // type A and E
    for(int i = 0; i <= maxn; i += 2) {
        int a = fountain_at[2][i], b = fountain_at[2][i + 2];
        if(a && b) {
            build_road_bench(a - 1, b - 1, mp(1, i + 1));
        }
        a = fountain_at[6][i], b = fountain_at[6][i + 2];
        if(a && b) {
            build_road_bench(a - 1, b - 1, mp(7, i + 1));
        }
    }
    // type B
    for(int i = 0; i <= maxn; i += 2) {
        int a = fountain_at[2][i], b = fountain_at[2][i + 2],
            c = fountain_at[4][i], d = fountain_at[4][i + 2];
        if((b && d) && (!a || !c)) {
            build_road_bench(b - 1, d - 1, mp(3, i + 1));
        }
    }
    // type C
    for(int i = 0; i <= maxn; i += 2) {
        int a = fountain_at[4][i], b = fountain_at[4][i + 2];
        if(a && b) {
            if(!bench_at[3][i + 1]) {
                build_road_bench(a - 1, b - 1, mp(3, i + 1));
            } else {
                build_road_bench(a - 1, b - 1, mp(5, i + 1));
            }
        }
    }
    // type D
    for(int i = 0; i <= maxn; i += 2) {
        int a = fountain_at[4][i], b = fountain_at[4][i + 2],
            c = fountain_at[6][i], d = fountain_at[6][i + 2];
        if((b && d) && (!a || !c)) {
            if(!bench_at[5][i + 1]) {
                build_road_bench(b - 1, d - 1, mp(5, i + 1));
            } else {
                build_road_bench(b - 1, d - 1, mp(5, i + 3));
            }
        }
    }
}

#undef x
#undef y
int construct_roads(vector<int> x, vector<int> y) {
    // edge case
    if (x.size() == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    // sample solution
    /*vector<int> u, v, a, b;
    u.push_back(0);
    v.push_back(1);
    a.push_back(x[0]+1);
    b.push_back(y[0]-1);
    build(u, v, a, b);*/
    n = x.size();
    if(!check_possibility(n, x, y)) {
        return 0;
    }
    X = x;
    Y = y;
    points.assign(n, fountain());
    for(int i = 0; i < n; i++) {
        points[i] = fountain(x[i], y[i], i);
        fountain_at[x[i]][y[i]] = i + 1;
    }
    solve();
    // build solution
    build(ans_u, ans_v, ans_a, ans_b);
    return 1;
}

/*
5
4 4
4 6
6 4
4 2
2 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
17 Correct 42 ms 13984 KB Output is correct
18 Correct 37 ms 13840 KB Output is correct
19 Correct 35 ms 13884 KB Output is correct
20 Correct 46 ms 13844 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 37 ms 13920 KB Output is correct
23 Correct 326 ms 43796 KB Output is correct
24 Correct 39 ms 13884 KB Output is correct
25 Correct 38 ms 13984 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 165 ms 25308 KB Output is correct
29 Correct 218 ms 31280 KB Output is correct
30 Correct 258 ms 37432 KB Output is correct
31 Correct 367 ms 43756 KB Output is correct
32 Correct 36 ms 13884 KB Output is correct
33 Correct 39 ms 13956 KB Output is correct
34 Correct 38 ms 13852 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 38 ms 14032 KB Output is correct
38 Correct 40 ms 13876 KB Output is correct
39 Correct 38 ms 13956 KB Output is correct
40 Correct 38 ms 13980 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 39 ms 13924 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 196 ms 28440 KB Output is correct
46 Correct 291 ms 35788 KB Output is correct
47 Correct 286 ms 36000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
17 Correct 42 ms 13984 KB Output is correct
18 Correct 37 ms 13840 KB Output is correct
19 Correct 35 ms 13884 KB Output is correct
20 Correct 46 ms 13844 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 37 ms 13920 KB Output is correct
23 Correct 326 ms 43796 KB Output is correct
24 Correct 39 ms 13884 KB Output is correct
25 Correct 38 ms 13984 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 165 ms 25308 KB Output is correct
29 Correct 218 ms 31280 KB Output is correct
30 Correct 258 ms 37432 KB Output is correct
31 Correct 367 ms 43756 KB Output is correct
32 Correct 36 ms 13884 KB Output is correct
33 Correct 39 ms 13956 KB Output is correct
34 Correct 38 ms 13852 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 38 ms 14032 KB Output is correct
38 Correct 40 ms 13876 KB Output is correct
39 Correct 38 ms 13956 KB Output is correct
40 Correct 38 ms 13980 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 39 ms 13924 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 196 ms 28440 KB Output is correct
46 Correct 291 ms 35788 KB Output is correct
47 Correct 286 ms 36000 KB Output is correct
48 Correct 36 ms 13872 KB Output is correct
49 Correct 37 ms 13876 KB Output is correct
50 Correct 36 ms 13972 KB Output is correct
51 Correct 41 ms 13960 KB Output is correct
52 Correct 38 ms 13964 KB Output is correct
53 Correct 46 ms 13884 KB Output is correct
54 Correct 39 ms 13896 KB Output is correct
55 Correct 310 ms 42880 KB Output is correct
56 Correct 47 ms 13884 KB Output is correct
57 Correct 38 ms 14112 KB Output is correct
58 Correct 47 ms 14688 KB Output is correct
59 Correct 5 ms 1108 KB Output is correct
60 Correct 152 ms 28284 KB Output is correct
61 Correct 213 ms 35440 KB Output is correct
62 Correct 313 ms 39144 KB Output is correct
63 Correct 401 ms 43080 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 38 ms 13968 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 335 ms 44380 KB Output is correct
68 Correct 332 ms 44376 KB Output is correct
69 Correct 350 ms 43812 KB Output is correct
70 Correct 3 ms 724 KB Output is correct
71 Correct 4 ms 980 KB Output is correct
72 Correct 189 ms 28520 KB Output is correct
73 Correct 348 ms 36020 KB Output is correct
74 Correct 439 ms 43812 KB Output is correct
75 Correct 371 ms 43260 KB Output is correct
76 Correct 359 ms 44276 KB Output is correct
77 Correct 3 ms 852 KB Output is correct
78 Correct 5 ms 1236 KB Output is correct
79 Correct 220 ms 29488 KB Output is correct
80 Correct 336 ms 38068 KB Output is correct
81 Correct 496 ms 45812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
17 Incorrect 39 ms 13924 KB Given structure is not connected: There is no path between vertices 0 and 1
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
17 Incorrect 533 ms 55428 KB Given structure is not connected: There is no path between vertices 0 and 1
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 38 ms 13956 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 42 ms 13952 KB Output is correct
5 Correct 38 ms 13924 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 171 ms 27944 KB Output is correct
10 Correct 50 ms 15188 KB Output is correct
11 Correct 93 ms 21452 KB Output is correct
12 Correct 54 ms 15952 KB Output is correct
13 Correct 21 ms 7204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 177 ms 27976 KB Output is correct
17 Correct 42 ms 13984 KB Output is correct
18 Correct 37 ms 13840 KB Output is correct
19 Correct 35 ms 13884 KB Output is correct
20 Correct 46 ms 13844 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 37 ms 13920 KB Output is correct
23 Correct 326 ms 43796 KB Output is correct
24 Correct 39 ms 13884 KB Output is correct
25 Correct 38 ms 13984 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 165 ms 25308 KB Output is correct
29 Correct 218 ms 31280 KB Output is correct
30 Correct 258 ms 37432 KB Output is correct
31 Correct 367 ms 43756 KB Output is correct
32 Correct 36 ms 13884 KB Output is correct
33 Correct 39 ms 13956 KB Output is correct
34 Correct 38 ms 13852 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 38 ms 14032 KB Output is correct
38 Correct 40 ms 13876 KB Output is correct
39 Correct 38 ms 13956 KB Output is correct
40 Correct 38 ms 13980 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 39 ms 13924 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 196 ms 28440 KB Output is correct
46 Correct 291 ms 35788 KB Output is correct
47 Correct 286 ms 36000 KB Output is correct
48 Correct 36 ms 13872 KB Output is correct
49 Correct 37 ms 13876 KB Output is correct
50 Correct 36 ms 13972 KB Output is correct
51 Correct 41 ms 13960 KB Output is correct
52 Correct 38 ms 13964 KB Output is correct
53 Correct 46 ms 13884 KB Output is correct
54 Correct 39 ms 13896 KB Output is correct
55 Correct 310 ms 42880 KB Output is correct
56 Correct 47 ms 13884 KB Output is correct
57 Correct 38 ms 14112 KB Output is correct
58 Correct 47 ms 14688 KB Output is correct
59 Correct 5 ms 1108 KB Output is correct
60 Correct 152 ms 28284 KB Output is correct
61 Correct 213 ms 35440 KB Output is correct
62 Correct 313 ms 39144 KB Output is correct
63 Correct 401 ms 43080 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 38 ms 13968 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 335 ms 44380 KB Output is correct
68 Correct 332 ms 44376 KB Output is correct
69 Correct 350 ms 43812 KB Output is correct
70 Correct 3 ms 724 KB Output is correct
71 Correct 4 ms 980 KB Output is correct
72 Correct 189 ms 28520 KB Output is correct
73 Correct 348 ms 36020 KB Output is correct
74 Correct 439 ms 43812 KB Output is correct
75 Correct 371 ms 43260 KB Output is correct
76 Correct 359 ms 44276 KB Output is correct
77 Correct 3 ms 852 KB Output is correct
78 Correct 5 ms 1236 KB Output is correct
79 Correct 220 ms 29488 KB Output is correct
80 Correct 336 ms 38068 KB Output is correct
81 Correct 496 ms 45812 KB Output is correct
82 Incorrect 39 ms 13924 KB Given structure is not connected: There is no path between vertices 0 and 1
83 Halted 0 ms 0 KB -