답안 #814402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
814402 2023-08-08T07:18:21 Z PixelCat 분수 공원 (IOI21_parks) C++17
55 / 100
1243 ms 91136 KB
#include "parks.h"

#ifdef NYAOWO
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 200'000;
const int MAXND = MAXN * 2;

struct SCC {
    vector<int> adj[MAXND + 10];
    vector<int> rev[MAXND + 10];
    int vis[MAXND + 10];
    vector<int> stk;
 
    void link(int x, int y) {
        adj[x].eb(y);
        rev[y].eb(x);
    }
    void bilink(int x, int y) {
        link(x, y);
        link(y, x);
    }
 
    void dfs1(int n) {
        if(vis[n] < 0) return;
        vis[n] = -1;
        for(auto &i:rev[n]) dfs1(i);
        stk.eb(n);
    }
    void dfs2(int n, int tag) {
        if(vis[n] != -1) return;
        vis[n] = tag;
        for(auto &i:adj[n]) dfs2(i, tag);
    }
    int build_scc(int n) {
        memset(vis, 0, sizeof(vis));
        For(i, 0, n - 1) dfs1(i);
        int cur_scc = 0;
        while(sz(stk)) {
            dfs2(stk.back(), cur_scc);
            while(sz(stk) && vis[stk.back()] != -1) stk.pop_back();
            cur_scc++;
        }
        return cur_scc;
    }
} ayaya;

struct DSU {
    int p[MAXN + 10];
    void init() {
        memset(p, -1, sizeof(p));
    }
    int find(int n) {
        if(p[n] < 0) return n;
        return p[n] = find(p[n]);
    }
    bool uni(int a, int b) {
        a = find(a); b = find(b);
        if(a == b) return false;
        p[b] = a;
        return true;
    }
} dsu;

struct PT {
    int id, x, y;
};

int construct_roads(std::vector<int> X, std::vector<int> Y) {
    if (sz(X) == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    int n = sz(X);

    map<pii, int> mp;
    For(i, 0, n - 1) {
        mp[pii(X[i], Y[i])] = i;
    }
    auto find = [&](int x, int y) {
        if(mp.count(pii(x, y))) return mp[pii(x, y)];
        return -1;
    };
    dsu.init();
    int cnt = 0;
    map<pii, int> hor, ver;
    vector<int> U(n - 1), V(n - 1), A(n - 1), B(n - 1);
    For(i, 0, n - 1) {
        int x = X[i], y = Y[i];
        auto link = [&](int x2, int y2) {
            int j = find(x2, y2);
            if(j >= 0 && dsu.uni(i, j)) {
                if(x2 == x) ver[pii(x, max(y, y2))] = cnt;
                else hor[pii(min(x, x2), y)] = cnt;
                U[cnt] = i;
                V[cnt] = j;
                cnt++;
            }
        };
        const int dx[4] = {0, 0, 2, -2};
        const int dy[4] = {2, -2, 0, 0};
        For(it, 0, 3) link(x + dx[it], y + dy[it]);
    }
    if(cnt != n - 1) return 0;

    for(auto &it:ver) {
        pii p; int id;
        tie(p, id) = it;
        int x, y;
        tie(x, y) = p;
        if(hor.count(pii(x - 2, y))) {
            int id2 = hor[pii(x - 2, y)];
            ayaya.link(id, id2);
            ayaya.link(id2 + n, id + n);
        }
        if(hor.count(pii(x - 2, y - 2))) {
            int id2 = hor[pii(x - 2, y - 2)];
            ayaya.link(id, id2 + n);
            ayaya.link(id2, id + n);
        }
        if(hor.count(pii(x, y))) {
            int id2 = hor[pii(x, y)];
            ayaya.link(id + n, id2);
            ayaya.link(id2 + n, id);
        }
        if(hor.count(pii(x, y - 2))) {
            int id2 = hor[pii(x, y - 2)];
            ayaya.link(id + n, id2 + n);
            ayaya.link(id2, id);
        }
        if(ver.count(pii(x + 2, y))) {
            int id2 = ver[pii(x + 2, y)];
            ayaya.link(id + n, id2 + n);
            ayaya.link(id2, id);
        }
    }
    for(auto &it:hor) {
        pii p; int id;
        tie(p, id) = it;
        int x, y;
        tie(x, y) = p;
        if(hor.count(pii(x, y - 2))) {
            int id2 = hor[pii(x, y - 2)];
            ayaya.link(id + n, id2 + n);
            ayaya.link(id2, id);
        }
    }
    ayaya.build_scc(n * 2);

    for(auto &it:ver) {
        pii p; int id;
        tie(p, id) = it;
        int x, y;
        tie(x, y) = p;
        int s1 = ayaya.vis[id];
        int s2 = ayaya.vis[id + n];
        if(s1 == s2) return 0;
        if(s1 < s2) {
            A[id] = x - 1;
            B[id] = y - 1;
        } else {
            A[id] = x + 1;
            B[id] = y - 1;
        }
    }
    for(auto &it:hor) {
        pii p; int id;
        tie(p, id) = it;
        int x, y;
        tie(x, y) = p;
        int s1 = ayaya.vis[id];
        int s2 = ayaya.vis[id + n];
        if(s1 == s2) return 0;
        if(s1 < s2) {
            A[id] = x + 1;
            B[id] = y + 1;
        } else {
            A[id] = x + 1;
            B[id] = y - 1;
        }
    }
    build(U, V, A, B);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
17 Correct 10 ms 21360 KB Output is correct
18 Correct 10 ms 21404 KB Output is correct
19 Correct 10 ms 21352 KB Output is correct
20 Correct 10 ms 21332 KB Output is correct
21 Correct 13 ms 19796 KB Output is correct
22 Correct 11 ms 21332 KB Output is correct
23 Correct 900 ms 75692 KB Output is correct
24 Correct 11 ms 21332 KB Output is correct
25 Correct 12 ms 21716 KB Output is correct
26 Correct 12 ms 20308 KB Output is correct
27 Correct 16 ms 20436 KB Output is correct
28 Correct 257 ms 43080 KB Output is correct
29 Correct 443 ms 54016 KB Output is correct
30 Correct 711 ms 64972 KB Output is correct
31 Correct 973 ms 75788 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 11 ms 21332 KB Output is correct
34 Correct 10 ms 21332 KB Output is correct
35 Correct 10 ms 19900 KB Output is correct
36 Correct 9 ms 19772 KB Output is correct
37 Correct 11 ms 21352 KB Output is correct
38 Correct 10 ms 21332 KB Output is correct
39 Correct 10 ms 21332 KB Output is correct
40 Correct 13 ms 21320 KB Output is correct
41 Correct 12 ms 19796 KB Output is correct
42 Correct 11 ms 21328 KB Output is correct
43 Correct 12 ms 20120 KB Output is correct
44 Correct 13 ms 20308 KB Output is correct
45 Correct 339 ms 48748 KB Output is correct
46 Correct 539 ms 61080 KB Output is correct
47 Correct 598 ms 61072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
17 Correct 10 ms 21360 KB Output is correct
18 Correct 10 ms 21404 KB Output is correct
19 Correct 10 ms 21352 KB Output is correct
20 Correct 10 ms 21332 KB Output is correct
21 Correct 13 ms 19796 KB Output is correct
22 Correct 11 ms 21332 KB Output is correct
23 Correct 900 ms 75692 KB Output is correct
24 Correct 11 ms 21332 KB Output is correct
25 Correct 12 ms 21716 KB Output is correct
26 Correct 12 ms 20308 KB Output is correct
27 Correct 16 ms 20436 KB Output is correct
28 Correct 257 ms 43080 KB Output is correct
29 Correct 443 ms 54016 KB Output is correct
30 Correct 711 ms 64972 KB Output is correct
31 Correct 973 ms 75788 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 11 ms 21332 KB Output is correct
34 Correct 10 ms 21332 KB Output is correct
35 Correct 10 ms 19900 KB Output is correct
36 Correct 9 ms 19772 KB Output is correct
37 Correct 11 ms 21352 KB Output is correct
38 Correct 10 ms 21332 KB Output is correct
39 Correct 10 ms 21332 KB Output is correct
40 Correct 13 ms 21320 KB Output is correct
41 Correct 12 ms 19796 KB Output is correct
42 Correct 11 ms 21328 KB Output is correct
43 Correct 12 ms 20120 KB Output is correct
44 Correct 13 ms 20308 KB Output is correct
45 Correct 339 ms 48748 KB Output is correct
46 Correct 539 ms 61080 KB Output is correct
47 Correct 598 ms 61072 KB Output is correct
48 Correct 13 ms 21332 KB Output is correct
49 Correct 13 ms 21412 KB Output is correct
50 Correct 10 ms 21420 KB Output is correct
51 Correct 13 ms 21332 KB Output is correct
52 Correct 14 ms 21332 KB Output is correct
53 Correct 11 ms 21332 KB Output is correct
54 Correct 10 ms 21332 KB Output is correct
55 Incorrect 814 ms 72888 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
17 Correct 11 ms 21332 KB Output is correct
18 Correct 11 ms 21376 KB Output is correct
19 Correct 10 ms 19764 KB Output is correct
20 Correct 1000 ms 91136 KB Output is correct
21 Correct 987 ms 87272 KB Output is correct
22 Correct 997 ms 87484 KB Output is correct
23 Correct 504 ms 54672 KB Output is correct
24 Correct 365 ms 38676 KB Output is correct
25 Correct 687 ms 51132 KB Output is correct
26 Correct 577 ms 51136 KB Output is correct
27 Correct 687 ms 60576 KB Output is correct
28 Correct 615 ms 60660 KB Output is correct
29 Correct 782 ms 60656 KB Output is correct
30 Correct 878 ms 60656 KB Output is correct
31 Correct 13 ms 21324 KB Output is correct
32 Correct 46 ms 25732 KB Output is correct
33 Correct 125 ms 29272 KB Output is correct
34 Correct 942 ms 90364 KB Output is correct
35 Correct 23 ms 21332 KB Output is correct
36 Correct 96 ms 27680 KB Output is correct
37 Correct 287 ms 35524 KB Output is correct
38 Correct 339 ms 45300 KB Output is correct
39 Correct 472 ms 54280 KB Output is correct
40 Correct 610 ms 63300 KB Output is correct
41 Correct 884 ms 72296 KB Output is correct
42 Correct 1243 ms 81336 KB Output is correct
43 Correct 13 ms 21416 KB Output is correct
44 Correct 10 ms 21372 KB Output is correct
45 Correct 9 ms 21332 KB Output is correct
46 Correct 10 ms 19796 KB Output is correct
47 Correct 13 ms 19796 KB Output is correct
48 Correct 12 ms 21400 KB Output is correct
49 Correct 9 ms 21332 KB Output is correct
50 Correct 11 ms 21332 KB Output is correct
51 Correct 8 ms 21332 KB Output is correct
52 Correct 11 ms 19796 KB Output is correct
53 Correct 9 ms 21332 KB Output is correct
54 Correct 10 ms 20180 KB Output is correct
55 Correct 12 ms 20308 KB Output is correct
56 Correct 330 ms 48684 KB Output is correct
57 Correct 525 ms 61088 KB Output is correct
58 Correct 607 ms 61016 KB Output is correct
59 Correct 9 ms 19796 KB Output is correct
60 Correct 11 ms 21412 KB Output is correct
61 Correct 11 ms 19796 KB Output is correct
62 Correct 572 ms 60468 KB Output is correct
63 Correct 598 ms 60468 KB Output is correct
64 Correct 664 ms 60304 KB Output is correct
65 Correct 15 ms 20436 KB Output is correct
66 Correct 20 ms 21204 KB Output is correct
67 Correct 332 ms 49312 KB Output is correct
68 Correct 587 ms 63328 KB Output is correct
69 Correct 956 ms 77288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
17 Correct 608 ms 60492 KB Output is correct
18 Correct 550 ms 60696 KB Output is correct
19 Correct 988 ms 90088 KB Output is correct
20 Correct 869 ms 78948 KB Output is correct
21 Correct 666 ms 63684 KB Output is correct
22 Correct 10 ms 21332 KB Output is correct
23 Correct 93 ms 30956 KB Output is correct
24 Correct 43 ms 22904 KB Output is correct
25 Correct 146 ms 30784 KB Output is correct
26 Correct 297 ms 38664 KB Output is correct
27 Correct 343 ms 50704 KB Output is correct
28 Correct 501 ms 58180 KB Output is correct
29 Correct 608 ms 65536 KB Output is correct
30 Correct 731 ms 72620 KB Output is correct
31 Correct 944 ms 80188 KB Output is correct
32 Correct 769 ms 74272 KB Output is correct
33 Correct 599 ms 60520 KB Output is correct
34 Correct 16 ms 20552 KB Output is correct
35 Correct 25 ms 21220 KB Output is correct
36 Correct 314 ms 49060 KB Output is correct
37 Correct 602 ms 62888 KB Output is correct
38 Correct 847 ms 76712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 19028 KB Output is correct
2 Correct 12 ms 21396 KB Output is correct
3 Correct 10 ms 19868 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21332 KB Output is correct
6 Correct 10 ms 19776 KB Output is correct
7 Correct 10 ms 19884 KB Output is correct
8 Correct 12 ms 19852 KB Output is correct
9 Correct 209 ms 41040 KB Output is correct
10 Correct 21 ms 23468 KB Output is correct
11 Correct 83 ms 31856 KB Output is correct
12 Correct 27 ms 24660 KB Output is correct
13 Correct 56 ms 26720 KB Output is correct
14 Correct 10 ms 19924 KB Output is correct
15 Correct 11 ms 20180 KB Output is correct
16 Correct 188 ms 40980 KB Output is correct
17 Correct 10 ms 21360 KB Output is correct
18 Correct 10 ms 21404 KB Output is correct
19 Correct 10 ms 21352 KB Output is correct
20 Correct 10 ms 21332 KB Output is correct
21 Correct 13 ms 19796 KB Output is correct
22 Correct 11 ms 21332 KB Output is correct
23 Correct 900 ms 75692 KB Output is correct
24 Correct 11 ms 21332 KB Output is correct
25 Correct 12 ms 21716 KB Output is correct
26 Correct 12 ms 20308 KB Output is correct
27 Correct 16 ms 20436 KB Output is correct
28 Correct 257 ms 43080 KB Output is correct
29 Correct 443 ms 54016 KB Output is correct
30 Correct 711 ms 64972 KB Output is correct
31 Correct 973 ms 75788 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 11 ms 21332 KB Output is correct
34 Correct 10 ms 21332 KB Output is correct
35 Correct 10 ms 19900 KB Output is correct
36 Correct 9 ms 19772 KB Output is correct
37 Correct 11 ms 21352 KB Output is correct
38 Correct 10 ms 21332 KB Output is correct
39 Correct 10 ms 21332 KB Output is correct
40 Correct 13 ms 21320 KB Output is correct
41 Correct 12 ms 19796 KB Output is correct
42 Correct 11 ms 21328 KB Output is correct
43 Correct 12 ms 20120 KB Output is correct
44 Correct 13 ms 20308 KB Output is correct
45 Correct 339 ms 48748 KB Output is correct
46 Correct 539 ms 61080 KB Output is correct
47 Correct 598 ms 61072 KB Output is correct
48 Correct 13 ms 21332 KB Output is correct
49 Correct 13 ms 21412 KB Output is correct
50 Correct 10 ms 21420 KB Output is correct
51 Correct 13 ms 21332 KB Output is correct
52 Correct 14 ms 21332 KB Output is correct
53 Correct 11 ms 21332 KB Output is correct
54 Correct 10 ms 21332 KB Output is correct
55 Incorrect 814 ms 72888 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -