Submission #814393

# Submission time Handle Problem Language Result Execution time Memory
814393 2023-08-08T07:14:30 Z PixelCat Fountain Parks (IOI21_parks) C++17
45 / 100
1004 ms 91084 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);
        }
    }
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
17 Correct 12 ms 21332 KB Output is correct
18 Correct 11 ms 21352 KB Output is correct
19 Correct 14 ms 21416 KB Output is correct
20 Correct 11 ms 21356 KB Output is correct
21 Correct 7 ms 19800 KB Output is correct
22 Correct 11 ms 21360 KB Output is correct
23 Incorrect 725 ms 75128 KB Tree @(3, 107989) appears more than once: for edges on positions 17500 and 20024
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
17 Correct 12 ms 21332 KB Output is correct
18 Correct 11 ms 21352 KB Output is correct
19 Correct 14 ms 21416 KB Output is correct
20 Correct 11 ms 21356 KB Output is correct
21 Correct 7 ms 19800 KB Output is correct
22 Correct 11 ms 21360 KB Output is correct
23 Incorrect 725 ms 75128 KB Tree @(3, 107989) appears more than once: for edges on positions 17500 and 20024
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
17 Correct 10 ms 21332 KB Output is correct
18 Correct 10 ms 21356 KB Output is correct
19 Correct 11 ms 19844 KB Output is correct
20 Correct 794 ms 91084 KB Output is correct
21 Correct 830 ms 87276 KB Output is correct
22 Correct 833 ms 87484 KB Output is correct
23 Correct 541 ms 54716 KB Output is correct
24 Correct 338 ms 38672 KB Output is correct
25 Correct 629 ms 51096 KB Output is correct
26 Correct 534 ms 51088 KB Output is correct
27 Correct 708 ms 60952 KB Output is correct
28 Correct 737 ms 61068 KB Output is correct
29 Correct 819 ms 60968 KB Output is correct
30 Correct 859 ms 60988 KB Output is correct
31 Correct 11 ms 21332 KB Output is correct
32 Correct 41 ms 25896 KB Output is correct
33 Correct 105 ms 29632 KB Output is correct
34 Correct 867 ms 90648 KB Output is correct
35 Correct 23 ms 21460 KB Output is correct
36 Correct 95 ms 27832 KB Output is correct
37 Correct 213 ms 35812 KB Output is correct
38 Correct 273 ms 45680 KB Output is correct
39 Correct 384 ms 54612 KB Output is correct
40 Correct 560 ms 63720 KB Output is correct
41 Correct 838 ms 72668 KB Output is correct
42 Correct 1004 ms 81812 KB Output is correct
43 Correct 11 ms 21332 KB Output is correct
44 Correct 13 ms 21364 KB Output is correct
45 Correct 13 ms 21352 KB Output is correct
46 Correct 13 ms 19796 KB Output is correct
47 Correct 12 ms 19796 KB Output is correct
48 Correct 12 ms 21416 KB Output is correct
49 Correct 11 ms 21364 KB Output is correct
50 Correct 11 ms 21360 KB Output is correct
51 Correct 12 ms 21332 KB Output is correct
52 Correct 11 ms 19848 KB Output is correct
53 Correct 11 ms 21332 KB Output is correct
54 Correct 12 ms 20144 KB Output is correct
55 Correct 14 ms 20308 KB Output is correct
56 Correct 330 ms 48960 KB Output is correct
57 Correct 495 ms 61452 KB Output is correct
58 Correct 514 ms 61492 KB Output is correct
59 Correct 11 ms 19924 KB Output is correct
60 Correct 11 ms 21332 KB Output is correct
61 Correct 10 ms 19876 KB Output is correct
62 Correct 535 ms 60884 KB Output is correct
63 Correct 557 ms 60948 KB Output is correct
64 Correct 576 ms 60736 KB Output is correct
65 Correct 15 ms 20436 KB Output is correct
66 Correct 21 ms 21084 KB Output is correct
67 Correct 305 ms 49564 KB Output is correct
68 Correct 602 ms 63700 KB Output is correct
69 Correct 919 ms 77644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
17 Correct 576 ms 60960 KB Output is correct
18 Correct 572 ms 61044 KB Output is correct
19 Correct 835 ms 90516 KB Output is correct
20 Correct 867 ms 79372 KB Output is correct
21 Correct 681 ms 63972 KB Output is correct
22 Correct 11 ms 21332 KB Output is correct
23 Correct 87 ms 31292 KB Output is correct
24 Correct 47 ms 23052 KB Output is correct
25 Correct 147 ms 31208 KB Output is correct
26 Correct 287 ms 39020 KB Output is correct
27 Correct 352 ms 51188 KB Output is correct
28 Correct 472 ms 58500 KB Output is correct
29 Correct 555 ms 65904 KB Output is correct
30 Correct 855 ms 72940 KB Output is correct
31 Correct 965 ms 80504 KB Output is correct
32 Correct 726 ms 74604 KB Output is correct
33 Correct 553 ms 60952 KB Output is correct
34 Correct 16 ms 20656 KB Output is correct
35 Correct 22 ms 21292 KB Output is correct
36 Correct 322 ms 49420 KB Output is correct
37 Correct 565 ms 63232 KB Output is correct
38 Correct 880 ms 77072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19028 KB Output is correct
2 Correct 10 ms 21416 KB Output is correct
3 Correct 9 ms 19796 KB Output is correct
4 Correct 9 ms 21384 KB Output is correct
5 Correct 9 ms 21332 KB Output is correct
6 Correct 9 ms 19840 KB Output is correct
7 Correct 10 ms 19796 KB Output is correct
8 Correct 10 ms 19796 KB Output is correct
9 Correct 202 ms 41036 KB Output is correct
10 Correct 21 ms 23508 KB Output is correct
11 Correct 85 ms 31920 KB Output is correct
12 Correct 26 ms 24560 KB Output is correct
13 Correct 49 ms 26792 KB Output is correct
14 Correct 12 ms 19924 KB Output is correct
15 Correct 12 ms 20180 KB Output is correct
16 Correct 198 ms 41012 KB Output is correct
17 Correct 12 ms 21332 KB Output is correct
18 Correct 11 ms 21352 KB Output is correct
19 Correct 14 ms 21416 KB Output is correct
20 Correct 11 ms 21356 KB Output is correct
21 Correct 7 ms 19800 KB Output is correct
22 Correct 11 ms 21360 KB Output is correct
23 Incorrect 725 ms 75128 KB Tree @(3, 107989) appears more than once: for edges on positions 17500 and 20024
24 Halted 0 ms 0 KB -