답안 #598583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598583 2022-07-18T14:25:58 Z MadokaMagicaFan 분수 공원 (IOI21_parks) C++17
30 / 100
549 ms 50340 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second
/* #define ONPC */

using vi = vector<int>;

const ll X= 2e5+10;

int p[X];

set<ll> bench;
set<ll> fount;
map<ll, int> fnt;

int ucount;

int getp(int x) { return p[x] = (p[x] == x) ? x : getp(p[x]); }
ll cord(ll x, ll y) { return y * X + x; }
void build (vi u, vi v, vi a, vi b);

void
uni(int a, int b)
{
    a = getp(a);
    b = getp(b);
    if (a == b) return;
    ++ucount;
    p[a] = b;
    return;
}

int
construct_roads(vi x, vi y)
{
    int n = sz(x);
    vector<ll> q;
    for (int i = 0; i < n; ++i) {
        p[i] = i;
        fount.insert(cord(x[i],y[i]));
        fnt[(cord(x[i],y[i]))] = i;
        q.pb(cord(x[i],y[i]));
    }

    sort(q.begin(), q.end());

    int a,b, ind, tind;

    vi u, v, ansa, ansb;
    for (int i = 0; i < n; ++i) {
        a = q[i] % X;
        b = q[i] / X;

        ind = fnt[q[i]];

        bool chk = (fount.find(cord(a,b+2)) != fount.end()) &&
                (fount.find(cord(a-2,b)) != fount.end()) &&
                (fount.find(cord(a-2,b+2)) != fount.end());

        if (fount.find(cord(a,b+2)) != fount.end() && !chk) {
            tind = fnt[cord(a,b+2)];
            if (getp(ind) != getp(tind)) {
                if (bench.find(cord(a-1,b+1)) == bench.end()) {
                    bench.insert(cord(a-1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a-1);
                    ansb.pb(b+1);
                    uni(ind,tind);
                } else if (bench.find(cord(a+1,b+1)) == bench.end()){
                    bench.insert(cord(a+1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b+1);
                    uni(ind,tind);
                }
            }
        }

        if (fount.find(cord(a+2,b)) != fount.end()) {
            tind = fnt[cord(a+2,b)];
            if (getp(ind) != getp(tind)) {
                if (bench.find(cord(a+1,b-1)) == bench.end()) {
                    bench.insert(cord(a+1,b-1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b-1);
                    uni(ind,tind);
                } else if (bench.find(cord(a+1,b+1)) == bench.end()){
                    bench.insert(cord(a+1,b+1));
                    u.pb(ind);
                    v.pb(tind);
                    ansa.pb(a+1);
                    ansb.pb(b+1);
                    uni(ind,tind);
                }
            }
        }
    }


    if (ucount != n-1) return 0;
    build(u, v, ansa, ansb);
    return 1;
}

#ifdef ONPC
void
build(vi u, vi v, vi a, vi b)
{

}

void
solve()
{
    int n;
    cin >> n;

    vi x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    cout << construct_roads(x, y) << endl;
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        solve();
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 452 ms 49248 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 576 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 149 ms 19992 KB Output is correct
29 Correct 284 ms 29676 KB Output is correct
30 Correct 335 ms 39912 KB Output is correct
31 Correct 443 ms 49248 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 316 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 193 ms 24860 KB Output is correct
46 Correct 321 ms 36644 KB Output is correct
47 Correct 296 ms 36508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 452 ms 49248 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 576 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 149 ms 19992 KB Output is correct
29 Correct 284 ms 29676 KB Output is correct
30 Correct 335 ms 39912 KB Output is correct
31 Correct 443 ms 49248 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 316 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 193 ms 24860 KB Output is correct
46 Correct 321 ms 36644 KB Output is correct
47 Correct 296 ms 36508 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 308 KB Output is correct
51 Correct 1 ms 316 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 308 KB Output is correct
55 Correct 458 ms 49136 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 3 ms 708 KB Output is correct
58 Correct 8 ms 1860 KB Output is correct
59 Correct 12 ms 2388 KB Output is correct
60 Correct 190 ms 24592 KB Output is correct
61 Correct 316 ms 34392 KB Output is correct
62 Correct 414 ms 41144 KB Output is correct
63 Correct 486 ms 49292 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 478 ms 49244 KB Output is correct
68 Correct 456 ms 49260 KB Output is correct
69 Correct 467 ms 49024 KB Output is correct
70 Correct 4 ms 1108 KB Output is correct
71 Correct 14 ms 1976 KB Output is correct
72 Correct 220 ms 24712 KB Output is correct
73 Correct 325 ms 37720 KB Output is correct
74 Correct 421 ms 49224 KB Output is correct
75 Correct 478 ms 49248 KB Output is correct
76 Correct 495 ms 49272 KB Output is correct
77 Correct 10 ms 1364 KB Output is correct
78 Correct 11 ms 2240 KB Output is correct
79 Correct 202 ms 24608 KB Output is correct
80 Correct 333 ms 37636 KB Output is correct
81 Correct 549 ms 49260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 540 ms 50164 KB Output is correct
21 Correct 488 ms 49968 KB Output is correct
22 Correct 484 ms 49888 KB Output is correct
23 Correct 356 ms 42824 KB Output is correct
24 Correct 254 ms 29144 KB Output is correct
25 Correct 344 ms 41880 KB Output is correct
26 Correct 442 ms 41892 KB Output is correct
27 Correct 528 ms 49228 KB Output is correct
28 Correct 493 ms 49272 KB Output is correct
29 Correct 441 ms 49224 KB Output is correct
30 Correct 426 ms 49268 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 18 ms 3268 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
17 Correct 422 ms 50340 KB Output is correct
18 Correct 424 ms 50036 KB Output is correct
19 Correct 422 ms 49920 KB Output is correct
20 Correct 404 ms 48344 KB Output is correct
21 Correct 352 ms 43512 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 39 ms 6796 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 204 ms 24760 KB Output is correct
10 Correct 13 ms 2812 KB Output is correct
11 Correct 76 ms 13392 KB Output is correct
12 Correct 18 ms 4020 KB Output is correct
13 Correct 47 ms 9540 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 193 ms 24812 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 452 ms 49248 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 576 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 149 ms 19992 KB Output is correct
29 Correct 284 ms 29676 KB Output is correct
30 Correct 335 ms 39912 KB Output is correct
31 Correct 443 ms 49248 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 316 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 193 ms 24860 KB Output is correct
46 Correct 321 ms 36644 KB Output is correct
47 Correct 296 ms 36508 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 308 KB Output is correct
51 Correct 1 ms 316 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 308 KB Output is correct
55 Correct 458 ms 49136 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 3 ms 708 KB Output is correct
58 Correct 8 ms 1860 KB Output is correct
59 Correct 12 ms 2388 KB Output is correct
60 Correct 190 ms 24592 KB Output is correct
61 Correct 316 ms 34392 KB Output is correct
62 Correct 414 ms 41144 KB Output is correct
63 Correct 486 ms 49292 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 478 ms 49244 KB Output is correct
68 Correct 456 ms 49260 KB Output is correct
69 Correct 467 ms 49024 KB Output is correct
70 Correct 4 ms 1108 KB Output is correct
71 Correct 14 ms 1976 KB Output is correct
72 Correct 220 ms 24712 KB Output is correct
73 Correct 325 ms 37720 KB Output is correct
74 Correct 421 ms 49224 KB Output is correct
75 Correct 478 ms 49248 KB Output is correct
76 Correct 495 ms 49272 KB Output is correct
77 Correct 10 ms 1364 KB Output is correct
78 Correct 11 ms 2240 KB Output is correct
79 Correct 202 ms 24608 KB Output is correct
80 Correct 333 ms 37636 KB Output is correct
81 Correct 549 ms 49260 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 540 ms 50164 KB Output is correct
86 Correct 488 ms 49968 KB Output is correct
87 Correct 484 ms 49888 KB Output is correct
88 Correct 356 ms 42824 KB Output is correct
89 Correct 254 ms 29144 KB Output is correct
90 Correct 344 ms 41880 KB Output is correct
91 Correct 442 ms 41892 KB Output is correct
92 Correct 528 ms 49228 KB Output is correct
93 Correct 493 ms 49272 KB Output is correct
94 Correct 441 ms 49224 KB Output is correct
95 Correct 426 ms 49268 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Incorrect 18 ms 3268 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -