답안 #598587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598587 2022-07-18T14:27:05 Z MadokaMagicaFan 분수 공원 (IOI21_parks) C++17
30 / 100
490 ms 48844 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+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 (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 (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 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 KB Output is correct
17 Correct 1 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 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 454 ms 47864 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 170 ms 19288 KB Output is correct
29 Correct 241 ms 28676 KB Output is correct
30 Correct 365 ms 38504 KB Output is correct
31 Correct 439 ms 47860 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 0 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 5 ms 992 KB Output is correct
45 Correct 190 ms 23968 KB Output is correct
46 Correct 311 ms 35388 KB Output is correct
47 Correct 314 ms 35376 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 KB Output is correct
17 Correct 1 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 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 454 ms 47864 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 170 ms 19288 KB Output is correct
29 Correct 241 ms 28676 KB Output is correct
30 Correct 365 ms 38504 KB Output is correct
31 Correct 439 ms 47860 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 0 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 5 ms 992 KB Output is correct
45 Correct 190 ms 23968 KB Output is correct
46 Correct 311 ms 35388 KB Output is correct
47 Correct 314 ms 35376 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 490 ms 47808 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 8 ms 1748 KB Output is correct
59 Correct 12 ms 2260 KB Output is correct
60 Correct 196 ms 23832 KB Output is correct
61 Correct 300 ms 33336 KB Output is correct
62 Correct 343 ms 39696 KB Output is correct
63 Correct 434 ms 48016 KB Output is correct
64 Correct 0 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 430 ms 47812 KB Output is correct
68 Correct 415 ms 47876 KB Output is correct
69 Correct 452 ms 47572 KB Output is correct
70 Correct 6 ms 1108 KB Output is correct
71 Correct 10 ms 1824 KB Output is correct
72 Correct 183 ms 23956 KB Output is correct
73 Correct 303 ms 36300 KB Output is correct
74 Correct 412 ms 47876 KB Output is correct
75 Correct 417 ms 47784 KB Output is correct
76 Correct 430 ms 47860 KB Output is correct
77 Correct 5 ms 1236 KB Output is correct
78 Correct 10 ms 2072 KB Output is correct
79 Correct 194 ms 23904 KB Output is correct
80 Correct 293 ms 36300 KB Output is correct
81 Correct 447 ms 47976 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 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 451 ms 48692 KB Output is correct
21 Correct 437 ms 48584 KB Output is correct
22 Correct 460 ms 48476 KB Output is correct
23 Correct 383 ms 41380 KB Output is correct
24 Correct 284 ms 27656 KB Output is correct
25 Correct 353 ms 40452 KB Output is correct
26 Correct 378 ms 40380 KB Output is correct
27 Correct 451 ms 47888 KB Output is correct
28 Correct 441 ms 47852 KB Output is correct
29 Correct 457 ms 47812 KB Output is correct
30 Correct 462 ms 47736 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 21 ms 3020 KB Solution announced impossible, but it is possible.
33 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 KB Output is correct
17 Correct 428 ms 48844 KB Output is correct
18 Correct 439 ms 48632 KB Output is correct
19 Correct 438 ms 48532 KB Output is correct
20 Correct 418 ms 46868 KB Output is correct
21 Correct 360 ms 42072 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 40 ms 6452 KB Solution announced impossible, but it is possible.
24 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 1 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 190 ms 23972 KB Output is correct
10 Correct 16 ms 2820 KB Output is correct
11 Correct 83 ms 12996 KB Output is correct
12 Correct 18 ms 3884 KB Output is correct
13 Correct 49 ms 9300 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 194 ms 23968 KB Output is correct
17 Correct 1 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 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 454 ms 47864 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 1016 KB Output is correct
28 Correct 170 ms 19288 KB Output is correct
29 Correct 241 ms 28676 KB Output is correct
30 Correct 365 ms 38504 KB Output is correct
31 Correct 439 ms 47860 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 0 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 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 5 ms 992 KB Output is correct
45 Correct 190 ms 23968 KB Output is correct
46 Correct 311 ms 35388 KB Output is correct
47 Correct 314 ms 35376 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 490 ms 47808 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 8 ms 1748 KB Output is correct
59 Correct 12 ms 2260 KB Output is correct
60 Correct 196 ms 23832 KB Output is correct
61 Correct 300 ms 33336 KB Output is correct
62 Correct 343 ms 39696 KB Output is correct
63 Correct 434 ms 48016 KB Output is correct
64 Correct 0 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 430 ms 47812 KB Output is correct
68 Correct 415 ms 47876 KB Output is correct
69 Correct 452 ms 47572 KB Output is correct
70 Correct 6 ms 1108 KB Output is correct
71 Correct 10 ms 1824 KB Output is correct
72 Correct 183 ms 23956 KB Output is correct
73 Correct 303 ms 36300 KB Output is correct
74 Correct 412 ms 47876 KB Output is correct
75 Correct 417 ms 47784 KB Output is correct
76 Correct 430 ms 47860 KB Output is correct
77 Correct 5 ms 1236 KB Output is correct
78 Correct 10 ms 2072 KB Output is correct
79 Correct 194 ms 23904 KB Output is correct
80 Correct 293 ms 36300 KB Output is correct
81 Correct 447 ms 47976 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 Correct 451 ms 48692 KB Output is correct
86 Correct 437 ms 48584 KB Output is correct
87 Correct 460 ms 48476 KB Output is correct
88 Correct 383 ms 41380 KB Output is correct
89 Correct 284 ms 27656 KB Output is correct
90 Correct 353 ms 40452 KB Output is correct
91 Correct 378 ms 40380 KB Output is correct
92 Correct 451 ms 47888 KB Output is correct
93 Correct 441 ms 47852 KB Output is correct
94 Correct 457 ms 47812 KB Output is correct
95 Correct 462 ms 47736 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Incorrect 21 ms 3020 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -