Submission #598570

# Submission time Handle Problem Language Result Execution time Memory
598570 2022-07-18T14:08:42 Z MadokaMagicaFan Fountain Parks (IOI21_parks) C++17
30 / 100
442 ms 48952 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,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 {
                    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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 442 ms 47788 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 153 ms 19308 KB Output is correct
29 Correct 233 ms 28632 KB Output is correct
30 Correct 344 ms 38508 KB Output is correct
31 Correct 409 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 1 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 1 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 3 ms 980 KB Output is correct
45 Correct 171 ms 23964 KB Output is correct
46 Correct 321 ms 35368 KB Output is correct
47 Correct 285 ms 35308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 442 ms 47788 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 153 ms 19308 KB Output is correct
29 Correct 233 ms 28632 KB Output is correct
30 Correct 344 ms 38508 KB Output is correct
31 Correct 409 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 1 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 1 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 3 ms 980 KB Output is correct
45 Correct 171 ms 23964 KB Output is correct
46 Correct 321 ms 35368 KB Output is correct
47 Correct 285 ms 35308 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 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 416 ms 47900 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 10 ms 2260 KB Output is correct
60 Correct 185 ms 23940 KB Output is correct
61 Correct 258 ms 33440 KB Output is correct
62 Correct 330 ms 39700 KB Output is correct
63 Correct 428 ms 48008 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 407 ms 47856 KB Output is correct
68 Correct 412 ms 47872 KB Output is correct
69 Correct 398 ms 47688 KB Output is correct
70 Correct 4 ms 1024 KB Output is correct
71 Correct 8 ms 1896 KB Output is correct
72 Correct 174 ms 23928 KB Output is correct
73 Correct 333 ms 36308 KB Output is correct
74 Correct 388 ms 47816 KB Output is correct
75 Correct 393 ms 47852 KB Output is correct
76 Correct 404 ms 47960 KB Output is correct
77 Correct 5 ms 1236 KB Output is correct
78 Correct 9 ms 2132 KB Output is correct
79 Correct 178 ms 24028 KB Output is correct
80 Correct 278 ms 36356 KB Output is correct
81 Correct 383 ms 47860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 412 ms 48692 KB Output is correct
21 Correct 400 ms 48644 KB Output is correct
22 Correct 412 ms 48464 KB Output is correct
23 Correct 329 ms 41396 KB Output is correct
24 Correct 272 ms 27684 KB Output is correct
25 Correct 332 ms 40336 KB Output is correct
26 Correct 358 ms 40396 KB Output is correct
27 Correct 424 ms 47740 KB Output is correct
28 Correct 433 ms 47816 KB Output is correct
29 Correct 410 ms 47912 KB Output is correct
30 Correct 393 ms 47728 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 18 ms 3136 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 KB Output is correct
17 Correct 428 ms 48952 KB Output is correct
18 Correct 394 ms 48688 KB Output is correct
19 Correct 409 ms 48604 KB Output is correct
20 Correct 387 ms 46876 KB Output is correct
21 Correct 332 ms 42040 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 36 ms 6400 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 175 ms 23948 KB Output is correct
10 Correct 10 ms 2692 KB Output is correct
11 Correct 70 ms 12908 KB Output is correct
12 Correct 16 ms 3876 KB Output is correct
13 Correct 41 ms 9228 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 23956 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 442 ms 47788 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 5 ms 1108 KB Output is correct
28 Correct 153 ms 19308 KB Output is correct
29 Correct 233 ms 28632 KB Output is correct
30 Correct 344 ms 38508 KB Output is correct
31 Correct 409 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 1 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 1 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 3 ms 980 KB Output is correct
45 Correct 171 ms 23964 KB Output is correct
46 Correct 321 ms 35368 KB Output is correct
47 Correct 285 ms 35308 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 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 416 ms 47900 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 10 ms 2260 KB Output is correct
60 Correct 185 ms 23940 KB Output is correct
61 Correct 258 ms 33440 KB Output is correct
62 Correct 330 ms 39700 KB Output is correct
63 Correct 428 ms 48008 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 407 ms 47856 KB Output is correct
68 Correct 412 ms 47872 KB Output is correct
69 Correct 398 ms 47688 KB Output is correct
70 Correct 4 ms 1024 KB Output is correct
71 Correct 8 ms 1896 KB Output is correct
72 Correct 174 ms 23928 KB Output is correct
73 Correct 333 ms 36308 KB Output is correct
74 Correct 388 ms 47816 KB Output is correct
75 Correct 393 ms 47852 KB Output is correct
76 Correct 404 ms 47960 KB Output is correct
77 Correct 5 ms 1236 KB Output is correct
78 Correct 9 ms 2132 KB Output is correct
79 Correct 178 ms 24028 KB Output is correct
80 Correct 278 ms 36356 KB Output is correct
81 Correct 383 ms 47860 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 412 ms 48692 KB Output is correct
86 Correct 400 ms 48644 KB Output is correct
87 Correct 412 ms 48464 KB Output is correct
88 Correct 329 ms 41396 KB Output is correct
89 Correct 272 ms 27684 KB Output is correct
90 Correct 332 ms 40336 KB Output is correct
91 Correct 358 ms 40396 KB Output is correct
92 Correct 424 ms 47740 KB Output is correct
93 Correct 433 ms 47816 KB Output is correct
94 Correct 410 ms 47912 KB Output is correct
95 Correct 393 ms 47728 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 18 ms 3136 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -