답안 #598568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598568 2022-07-18T14:05:39 Z MadokaMagicaFan 분수 공원 (IOI21_parks) C++17
30 / 100
432 ms 51212 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]];

        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);
                } else {
                    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()) {
            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_raods(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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 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 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 430 ms 49428 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1108 KB Output is correct
28 Correct 145 ms 19928 KB Output is correct
29 Correct 226 ms 29680 KB Output is correct
30 Correct 386 ms 39804 KB Output is correct
31 Correct 414 ms 49512 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 0 ms 312 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 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 4 ms 960 KB Output is correct
45 Correct 214 ms 24776 KB Output is correct
46 Correct 286 ms 36616 KB Output is correct
47 Correct 298 ms 36624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 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 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 430 ms 49428 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1108 KB Output is correct
28 Correct 145 ms 19928 KB Output is correct
29 Correct 226 ms 29680 KB Output is correct
30 Correct 386 ms 39804 KB Output is correct
31 Correct 414 ms 49512 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 0 ms 312 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 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 4 ms 960 KB Output is correct
45 Correct 214 ms 24776 KB Output is correct
46 Correct 286 ms 36616 KB Output is correct
47 Correct 298 ms 36624 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 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 0 ms 212 KB Output is correct
55 Correct 432 ms 49424 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 9 ms 1820 KB Output is correct
59 Correct 14 ms 2412 KB Output is correct
60 Correct 188 ms 24616 KB Output is correct
61 Correct 262 ms 34424 KB Output is correct
62 Correct 325 ms 41120 KB Output is correct
63 Correct 412 ms 49528 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 312 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 402 ms 49440 KB Output is correct
68 Correct 401 ms 49432 KB Output is correct
69 Correct 409 ms 49328 KB Output is correct
70 Correct 4 ms 1108 KB Output is correct
71 Correct 9 ms 1948 KB Output is correct
72 Correct 215 ms 24688 KB Output is correct
73 Correct 281 ms 37640 KB Output is correct
74 Correct 398 ms 49560 KB Output is correct
75 Correct 400 ms 49520 KB Output is correct
76 Correct 430 ms 49512 KB Output is correct
77 Correct 5 ms 1364 KB Output is correct
78 Correct 13 ms 2144 KB Output is correct
79 Correct 194 ms 24616 KB Output is correct
80 Correct 283 ms 37760 KB Output is correct
81 Correct 387 ms 49516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 420 ms 51212 KB Output is correct
21 Correct 413 ms 50872 KB Output is correct
22 Correct 415 ms 50868 KB Output is correct
23 Correct 324 ms 43204 KB Output is correct
24 Correct 270 ms 29368 KB Output is correct
25 Correct 331 ms 42032 KB Output is correct
26 Correct 372 ms 42004 KB Output is correct
27 Correct 407 ms 49428 KB Output is correct
28 Correct 408 ms 49400 KB Output is correct
29 Correct 393 ms 49428 KB Output is correct
30 Correct 390 ms 49396 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 16 ms 3252 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 KB Output is correct
17 Correct 414 ms 50800 KB Output is correct
18 Correct 410 ms 50792 KB Output is correct
19 Correct 430 ms 50856 KB Output is correct
20 Correct 403 ms 48372 KB Output is correct
21 Correct 359 ms 43456 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 44 ms 6900 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 24728 KB Output is correct
10 Correct 11 ms 2820 KB Output is correct
11 Correct 74 ms 13340 KB Output is correct
12 Correct 16 ms 4052 KB Output is correct
13 Correct 44 ms 9528 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 180 ms 24772 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 1 ms 212 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 430 ms 49428 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1108 KB Output is correct
28 Correct 145 ms 19928 KB Output is correct
29 Correct 226 ms 29680 KB Output is correct
30 Correct 386 ms 39804 KB Output is correct
31 Correct 414 ms 49512 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 0 ms 312 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 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 708 KB Output is correct
44 Correct 4 ms 960 KB Output is correct
45 Correct 214 ms 24776 KB Output is correct
46 Correct 286 ms 36616 KB Output is correct
47 Correct 298 ms 36624 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 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 0 ms 212 KB Output is correct
55 Correct 432 ms 49424 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 9 ms 1820 KB Output is correct
59 Correct 14 ms 2412 KB Output is correct
60 Correct 188 ms 24616 KB Output is correct
61 Correct 262 ms 34424 KB Output is correct
62 Correct 325 ms 41120 KB Output is correct
63 Correct 412 ms 49528 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 312 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 402 ms 49440 KB Output is correct
68 Correct 401 ms 49432 KB Output is correct
69 Correct 409 ms 49328 KB Output is correct
70 Correct 4 ms 1108 KB Output is correct
71 Correct 9 ms 1948 KB Output is correct
72 Correct 215 ms 24688 KB Output is correct
73 Correct 281 ms 37640 KB Output is correct
74 Correct 398 ms 49560 KB Output is correct
75 Correct 400 ms 49520 KB Output is correct
76 Correct 430 ms 49512 KB Output is correct
77 Correct 5 ms 1364 KB Output is correct
78 Correct 13 ms 2144 KB Output is correct
79 Correct 194 ms 24616 KB Output is correct
80 Correct 283 ms 37760 KB Output is correct
81 Correct 387 ms 49516 KB Output is correct
82 Correct 1 ms 308 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 312 KB Output is correct
85 Correct 420 ms 51212 KB Output is correct
86 Correct 413 ms 50872 KB Output is correct
87 Correct 415 ms 50868 KB Output is correct
88 Correct 324 ms 43204 KB Output is correct
89 Correct 270 ms 29368 KB Output is correct
90 Correct 331 ms 42032 KB Output is correct
91 Correct 372 ms 42004 KB Output is correct
92 Correct 407 ms 49428 KB Output is correct
93 Correct 408 ms 49400 KB Output is correct
94 Correct 393 ms 49428 KB Output is correct
95 Correct 390 ms 49396 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 16 ms 3252 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -