답안 #697992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697992 2023-02-11T17:53:51 Z Duy_e Stranded Far From Home (BOI22_island) C++14
100 / 100
650 ms 118580 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
 
const long long INF = 1e18;
const long long N = 2e5 + 5;
ll s[N], n, m, f[N], pos[N], ans[N];
pii a[N];
ll nxt[N];
 
vector <int> d[N];
 
namespace DSU {
    ll par[N], sz[N];
 
    void init() {
        rep(i, 1, n) par[i] = i, sz[i] = s[i];
    }
 
    int find(int u) {
        return u == par[u] ? u : par[u] = find(par[u]);
    }
 
    void uni(int u, int v) {
        u = find(u); v = find(v);
        if (u == v) return;
        par[u] = v;
        sz[v] += sz[u];
    }
}
 
namespace DSU_set_merge {
    set <pii> st[N];
    int par[N];
 
    void init() {
        rep(i, 1, n) {
            par[i] = i;
            for (int v: d[i]) if (s[v] >= s[i])
                st[i].insert(pii(s[v], v));
        }
    }
 
    int find(int u) {
        return u == par[u] ? u : par[u] = find(par[u]);
    }
 
    void uni(int u, int v) {
        u = find(u); v = find(v);
        if (u == v) return;
        if (st[u].size() > st[v].size()) swap(u, v);
        st[v].insert(st[u].begin(), st[u].end());
        par[u] = v;
    }
 
    int find_greater(int u, pii x) {
        int rt = find(u);
        auto it = st[rt].upper_bound(x);
        if (it != st[rt].end()) return it->nd;
        return 0;
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    //freopen("island.inp", "r", stdin);
    //freopen("island.out", "w", stdout);
 
    cin >> n >> m;
    rep(i, 1, n) {
        cin >> s[i];
        a[i] = {s[i], i};
    }
 
 
    rep(i, 1, m) {
        int u, v;
        cin >> u >> v;
        d[u].push_back(v);
        d[v].push_back(u);
    }
 
    DSU :: init();
    DSU_set_merge :: init();
 
    sort(a + 1, a + 1 + n);
    rep(i, 1, n) pos[a[i].nd] = i;
 
    s[0] = 2e9;
    rep(i, 1, n) {
        int u = a[i].nd;
        nxt[u] = 0;
        for (int v: d[u]) {
 
            if (s[v] <= s[u]) {
                DSU_set_merge :: uni(u, v);
                int tmp = DSU_set_merge :: find_greater(v, a[i]);
                if (s[tmp] <= s[nxt[u]])
                    nxt[u] = tmp;
            } else {
                if (s[v] <= s[nxt[u]])
                    nxt[u] = v;
            }
 
            if (s[v] <= s[u] && pos[v] < pos[u])
                DSU :: uni(u, v);
        }
 
        if (nxt[u] == 0) nxt[u] = u;
        f[u] = DSU :: sz[DSU :: find(u)];
        //cout << a[i].st << ' ' << a[i].nd << ' ' << nxt[u] << ' ' << f[u] << '\n';
    }
 
    ans[a[n].nd] = true;
    rrep(i, n - 1, 1) {
        int u = a[i].nd;
        int v = nxt[u];
        ans[u] = f[u] >= s[v] && ans[v];
    }
 
    rep(i, 1, n) cout << ans[i];
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 10 ms 14888 KB Output is correct
5 Correct 10 ms 14960 KB Output is correct
6 Correct 11 ms 15084 KB Output is correct
7 Correct 10 ms 14932 KB Output is correct
8 Correct 9 ms 14824 KB Output is correct
9 Correct 9 ms 14960 KB Output is correct
10 Correct 10 ms 15076 KB Output is correct
11 Correct 9 ms 15084 KB Output is correct
12 Correct 10 ms 15168 KB Output is correct
13 Correct 9 ms 15060 KB Output is correct
14 Correct 10 ms 15080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14420 KB Output is correct
2 Correct 8 ms 14440 KB Output is correct
3 Correct 233 ms 62792 KB Output is correct
4 Correct 258 ms 74700 KB Output is correct
5 Correct 373 ms 82248 KB Output is correct
6 Correct 371 ms 86572 KB Output is correct
7 Correct 393 ms 85432 KB Output is correct
8 Correct 440 ms 73560 KB Output is correct
9 Correct 348 ms 99600 KB Output is correct
10 Correct 175 ms 49272 KB Output is correct
11 Correct 347 ms 61796 KB Output is correct
12 Correct 505 ms 81320 KB Output is correct
13 Correct 309 ms 73476 KB Output is correct
14 Correct 334 ms 74676 KB Output is correct
15 Correct 214 ms 61036 KB Output is correct
16 Correct 156 ms 60624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 440 ms 98544 KB Output is correct
3 Correct 419 ms 98124 KB Output is correct
4 Correct 373 ms 73548 KB Output is correct
5 Correct 318 ms 77540 KB Output is correct
6 Correct 405 ms 97168 KB Output is correct
7 Correct 250 ms 60836 KB Output is correct
8 Correct 265 ms 60892 KB Output is correct
9 Correct 153 ms 60376 KB Output is correct
10 Correct 225 ms 55236 KB Output is correct
11 Correct 278 ms 72648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 474 ms 76556 KB Output is correct
3 Correct 462 ms 80452 KB Output is correct
4 Correct 462 ms 86932 KB Output is correct
5 Correct 626 ms 109092 KB Output is correct
6 Correct 601 ms 94008 KB Output is correct
7 Correct 318 ms 61884 KB Output is correct
8 Correct 228 ms 67220 KB Output is correct
9 Correct 277 ms 54924 KB Output is correct
10 Correct 604 ms 118504 KB Output is correct
11 Correct 254 ms 70804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 10 ms 14888 KB Output is correct
5 Correct 10 ms 14960 KB Output is correct
6 Correct 11 ms 15084 KB Output is correct
7 Correct 10 ms 14932 KB Output is correct
8 Correct 9 ms 14824 KB Output is correct
9 Correct 9 ms 14960 KB Output is correct
10 Correct 10 ms 15076 KB Output is correct
11 Correct 9 ms 15084 KB Output is correct
12 Correct 10 ms 15168 KB Output is correct
13 Correct 9 ms 15060 KB Output is correct
14 Correct 10 ms 15080 KB Output is correct
15 Correct 10 ms 14420 KB Output is correct
16 Correct 8 ms 14440 KB Output is correct
17 Correct 233 ms 62792 KB Output is correct
18 Correct 258 ms 74700 KB Output is correct
19 Correct 373 ms 82248 KB Output is correct
20 Correct 371 ms 86572 KB Output is correct
21 Correct 393 ms 85432 KB Output is correct
22 Correct 440 ms 73560 KB Output is correct
23 Correct 348 ms 99600 KB Output is correct
24 Correct 175 ms 49272 KB Output is correct
25 Correct 347 ms 61796 KB Output is correct
26 Correct 505 ms 81320 KB Output is correct
27 Correct 309 ms 73476 KB Output is correct
28 Correct 334 ms 74676 KB Output is correct
29 Correct 214 ms 61036 KB Output is correct
30 Correct 156 ms 60624 KB Output is correct
31 Correct 8 ms 14420 KB Output is correct
32 Correct 440 ms 98544 KB Output is correct
33 Correct 419 ms 98124 KB Output is correct
34 Correct 373 ms 73548 KB Output is correct
35 Correct 318 ms 77540 KB Output is correct
36 Correct 405 ms 97168 KB Output is correct
37 Correct 250 ms 60836 KB Output is correct
38 Correct 265 ms 60892 KB Output is correct
39 Correct 153 ms 60376 KB Output is correct
40 Correct 225 ms 55236 KB Output is correct
41 Correct 278 ms 72648 KB Output is correct
42 Correct 8 ms 14420 KB Output is correct
43 Correct 474 ms 76556 KB Output is correct
44 Correct 462 ms 80452 KB Output is correct
45 Correct 462 ms 86932 KB Output is correct
46 Correct 626 ms 109092 KB Output is correct
47 Correct 601 ms 94008 KB Output is correct
48 Correct 318 ms 61884 KB Output is correct
49 Correct 228 ms 67220 KB Output is correct
50 Correct 277 ms 54924 KB Output is correct
51 Correct 604 ms 118504 KB Output is correct
52 Correct 254 ms 70804 KB Output is correct
53 Correct 8 ms 14428 KB Output is correct
54 Correct 9 ms 14428 KB Output is correct
55 Correct 9 ms 14388 KB Output is correct
56 Correct 10 ms 14872 KB Output is correct
57 Correct 12 ms 15060 KB Output is correct
58 Correct 10 ms 15128 KB Output is correct
59 Correct 11 ms 14892 KB Output is correct
60 Correct 10 ms 14804 KB Output is correct
61 Correct 10 ms 14964 KB Output is correct
62 Correct 11 ms 15184 KB Output is correct
63 Correct 9 ms 15060 KB Output is correct
64 Correct 11 ms 15060 KB Output is correct
65 Correct 9 ms 15088 KB Output is correct
66 Correct 10 ms 15076 KB Output is correct
67 Correct 247 ms 62472 KB Output is correct
68 Correct 260 ms 74676 KB Output is correct
69 Correct 377 ms 81948 KB Output is correct
70 Correct 381 ms 86356 KB Output is correct
71 Correct 415 ms 85216 KB Output is correct
72 Correct 441 ms 73404 KB Output is correct
73 Correct 319 ms 99424 KB Output is correct
74 Correct 181 ms 49100 KB Output is correct
75 Correct 385 ms 61668 KB Output is correct
76 Correct 493 ms 81268 KB Output is correct
77 Correct 317 ms 73484 KB Output is correct
78 Correct 310 ms 74592 KB Output is correct
79 Correct 215 ms 60864 KB Output is correct
80 Correct 158 ms 60468 KB Output is correct
81 Correct 405 ms 98096 KB Output is correct
82 Correct 441 ms 97908 KB Output is correct
83 Correct 295 ms 73332 KB Output is correct
84 Correct 291 ms 77328 KB Output is correct
85 Correct 460 ms 97236 KB Output is correct
86 Correct 233 ms 60904 KB Output is correct
87 Correct 241 ms 60876 KB Output is correct
88 Correct 211 ms 55164 KB Output is correct
89 Correct 256 ms 72604 KB Output is correct
90 Correct 438 ms 76292 KB Output is correct
91 Correct 470 ms 80444 KB Output is correct
92 Correct 464 ms 87036 KB Output is correct
93 Correct 602 ms 108884 KB Output is correct
94 Correct 600 ms 93792 KB Output is correct
95 Correct 310 ms 61596 KB Output is correct
96 Correct 199 ms 67224 KB Output is correct
97 Correct 302 ms 54824 KB Output is correct
98 Correct 650 ms 118580 KB Output is correct
99 Correct 260 ms 70656 KB Output is correct
100 Correct 118 ms 29900 KB Output is correct
101 Correct 435 ms 80468 KB Output is correct
102 Correct 517 ms 84112 KB Output is correct
103 Correct 430 ms 62056 KB Output is correct
104 Correct 401 ms 70180 KB Output is correct