답안 #1070414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070414 2024-08-22T14:03:02 Z Arapak 분수 공원 (IOI21_parks) C++17
30 / 100
280 ms 41340 KB
#include "parks.h"
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

#ifdef DEBUG
auto& operator<<(auto &os, const pair<auto,auto> &p) {
    return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto &os, const auto &v) {
    os<<"{";
    for(auto it=begin(v);it!=end(v);++it) {
        if(it != begin(v)) os<<", ";
        os<<(*it);
    }
    return os<<"}";
}

void dbg_out(auto... x) {
    ((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

struct UF {
    vi e;
    UF(int n) : e(n, -1) {}
    bool sameSet(int a, int b) { return find(a) == find(b); }
    int size(int x) { return -e[find(x)]; }
    int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
    bool join(int a, int b) {
        a = find(a), b = find(b);
        if (a == b) return false;
        if (e[a] > e[b]) swap(a, b);
        e[a] += e[b]; e[b] = a;
        return true;
    }
};

struct Fountain {
    int x, y, index;

    friend bool operator<(const Fountain &a, const Fountain &b) {
        return tie(a.x, a.y) < tie(b.x, b.y);
    }
};

struct Bench {
    int a, b;
    int x, y;

    friend bool operator<(const Bench &a, const Bench &b) {
        return tie(a.x, a.y) < tie(b.x, b.y);
    }
};

void build_from_benches(set<Bench> &benches) {
    vi u, v, a, b;
    for(auto bench : benches) {
        u.push_back(bench.a);
        v.push_back(bench.b);
        a.push_back(bench.x);
        b.push_back(bench.y);
    }
    build(u, v, a, b);
}

int construct_roads(vi x, vi y) {
    int n = sz(x);
    dbg(x, y);
    set<Fountain> s;
    rep(i,0,n) s.insert({x[i], y[i], i});
    set<Bench> benches;
    UF uf(n);
    for(auto f : s) {
        {
            auto it = s.find({f.x - 2, f.y, -1});
            if(it != s.end()) {
                auto t = *it;
                if(uf.find(f.index) != uf.find(t.index)) {
                    Bench b;
                    b.a = f.index;
                    b.b = t.index;
                    b.x = f.x - 1;

                    b.y = f.y - 1;
                    if(benches.count(b))
                        b.y = f.y + 1;
                    if(benches.count(b))
                        return 0;
                    benches.insert(b);
                    uf.join(f.index, t.index);
                }
            }
        }

        {
            auto it = s.find({f.x, f.y - 2, -1});
            if(it != s.end()) {
                auto t = *it;
                if(uf.find(f.index) != uf.find(t.index)) {
                    Bench b;
                    b.a = f.index;
                    b.b = t.index;
                    b.y = f.y - 1;

                    b.x = f.x - 1;
                    if(benches.count(b))
                        b.x = f.x + 1;
                    if(benches.count(b))
                        return 0;
                    benches.insert(b);
                    uf.join(f.index, t.index);
                }
            }
        }
    }
    int index = uf.find(0);
    rep(i,0,n)
        if(uf.find(i) != index)
            return 0;
    build_from_benches(benches);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 279 ms 40364 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 86 ms 16420 KB Output is correct
29 Correct 139 ms 24608 KB Output is correct
30 Correct 203 ms 32488 KB Output is correct
31 Correct 258 ms 40604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 432 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 102 ms 20356 KB Output is correct
46 Correct 177 ms 29568 KB Output is correct
47 Correct 159 ms 29356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 279 ms 40364 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 86 ms 16420 KB Output is correct
29 Correct 139 ms 24608 KB Output is correct
30 Correct 203 ms 32488 KB Output is correct
31 Correct 258 ms 40604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 432 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 102 ms 20356 KB Output is correct
46 Correct 177 ms 29568 KB Output is correct
47 Correct 159 ms 29356 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 274 ms 40468 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 5 ms 1548 KB Output is correct
59 Correct 7 ms 1876 KB Output is correct
60 Correct 113 ms 20412 KB Output is correct
61 Correct 169 ms 27308 KB Output is correct
62 Correct 219 ms 33528 KB Output is correct
63 Correct 263 ms 40388 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 253 ms 40440 KB Output is correct
68 Correct 256 ms 40608 KB Output is correct
69 Correct 244 ms 40216 KB Output is correct
70 Correct 3 ms 856 KB Output is correct
71 Correct 5 ms 1628 KB Output is correct
72 Correct 99 ms 20512 KB Output is correct
73 Correct 167 ms 30380 KB Output is correct
74 Correct 238 ms 40368 KB Output is correct
75 Correct 258 ms 40360 KB Output is correct
76 Correct 240 ms 40532 KB Output is correct
77 Correct 3 ms 1112 KB Output is correct
78 Correct 6 ms 1628 KB Output is correct
79 Correct 113 ms 20412 KB Output is correct
80 Correct 173 ms 30608 KB Output is correct
81 Correct 255 ms 40600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 244 ms 41340 KB Output is correct
21 Correct 244 ms 41124 KB Output is correct
22 Correct 243 ms 41128 KB Output is correct
23 Correct 202 ms 34980 KB Output is correct
24 Correct 117 ms 18424 KB Output is correct
25 Correct 204 ms 30804 KB Output is correct
26 Correct 211 ms 30804 KB Output is correct
27 Correct 272 ms 40472 KB Output is correct
28 Correct 250 ms 40364 KB Output is correct
29 Correct 259 ms 40356 KB Output is correct
30 Correct 280 ms 40368 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 5 ms 1628 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
17 Correct 259 ms 40736 KB Output is correct
18 Correct 245 ms 40876 KB Output is correct
19 Correct 251 ms 41116 KB Output is correct
20 Correct 259 ms 39632 KB Output is correct
21 Correct 229 ms 35472 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Incorrect 13 ms 3416 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 110 ms 20440 KB Output is correct
10 Correct 8 ms 2652 KB Output is correct
11 Correct 53 ms 11208 KB Output is correct
12 Correct 12 ms 3672 KB Output is correct
13 Correct 30 ms 6952 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 109 ms 20512 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 279 ms 40364 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 86 ms 16420 KB Output is correct
29 Correct 139 ms 24608 KB Output is correct
30 Correct 203 ms 32488 KB Output is correct
31 Correct 258 ms 40604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 432 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 102 ms 20356 KB Output is correct
46 Correct 177 ms 29568 KB Output is correct
47 Correct 159 ms 29356 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 274 ms 40468 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 5 ms 1548 KB Output is correct
59 Correct 7 ms 1876 KB Output is correct
60 Correct 113 ms 20412 KB Output is correct
61 Correct 169 ms 27308 KB Output is correct
62 Correct 219 ms 33528 KB Output is correct
63 Correct 263 ms 40388 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 253 ms 40440 KB Output is correct
68 Correct 256 ms 40608 KB Output is correct
69 Correct 244 ms 40216 KB Output is correct
70 Correct 3 ms 856 KB Output is correct
71 Correct 5 ms 1628 KB Output is correct
72 Correct 99 ms 20512 KB Output is correct
73 Correct 167 ms 30380 KB Output is correct
74 Correct 238 ms 40368 KB Output is correct
75 Correct 258 ms 40360 KB Output is correct
76 Correct 240 ms 40532 KB Output is correct
77 Correct 3 ms 1112 KB Output is correct
78 Correct 6 ms 1628 KB Output is correct
79 Correct 113 ms 20412 KB Output is correct
80 Correct 173 ms 30608 KB Output is correct
81 Correct 255 ms 40600 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 244 ms 41340 KB Output is correct
86 Correct 244 ms 41124 KB Output is correct
87 Correct 243 ms 41128 KB Output is correct
88 Correct 202 ms 34980 KB Output is correct
89 Correct 117 ms 18424 KB Output is correct
90 Correct 204 ms 30804 KB Output is correct
91 Correct 211 ms 30804 KB Output is correct
92 Correct 272 ms 40472 KB Output is correct
93 Correct 250 ms 40364 KB Output is correct
94 Correct 259 ms 40356 KB Output is correct
95 Correct 280 ms 40368 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Incorrect 5 ms 1628 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -