답안 #884656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884656 2023-12-07T21:58:28 Z TAhmed33 Stranded Far From Home (BOI22_island) C++
100 / 100
865 ms 54596 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5 + 25;
bool ok[MAXN];
set <int> pp;
int cnt[MAXN];
vector <pair <int, int>> edges;
int par[MAXN], sum[MAXN];
set <int> comp[MAXN];
set <pair <int, int>> valid;
void init () {
    for (int i = 1; i < MAXN; i++) {
        par[i] = i;
        ok[i] = 1;
        sum[i] = cnt[i];
        comp[i].insert(i);
        valid.insert({sum[i], i});
    }
}
int find (int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
}
void merge (int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if ((int)comp[x].size() > (int)comp[y].size()) swap(x, y);
    valid.erase({sum[x], x});
    valid.erase({sum[y], y});
    par[x] = y; sum[y] += sum[x];
    valid.insert({sum[y], y});
    for (auto i : comp[x]) comp[y].insert(i);
    comp[x].clear();
}
signed main () {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> cnt[i];
        pp.insert(cnt[i]);
    }
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        edges.push_back({a, b});
    }
    int z = pp.size();
    sort(edges.begin(), edges.end(), [&] (pair <int, int> &a, pair <int, int> &b) {
        return max(cnt[a.first], cnt[a.second]) > max(cnt[b.first], cnt[b.second]);
    });
    init();
    for (int l = 0; l + 1 < z; l++) {
        auto i = *(pp.begin()); pp.erase(i); 
        while (!edges.empty() && max(cnt[edges.back().first], cnt[edges.back().second]) == i) {
            merge(edges.back().first, edges.back().second);
            edges.pop_back();
        }
        auto y = *(pp.begin());
        while (!valid.empty()) {
            auto k = *(valid.begin());
            if (k.first >= y) break;
            valid.erase(k);
            for (auto j : comp[k.second]) {
                ok[j] = 0;
            }
            comp[k.second].clear();
        }
    }   
    for (int i = 1; i <= n; i++) cout << ok[i];
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 34888 KB Output is correct
2 Correct 67 ms 35060 KB Output is correct
3 Correct 50 ms 35036 KB Output is correct
4 Correct 69 ms 35156 KB Output is correct
5 Correct 68 ms 35164 KB Output is correct
6 Correct 65 ms 34896 KB Output is correct
7 Correct 67 ms 35152 KB Output is correct
8 Correct 72 ms 35412 KB Output is correct
9 Correct 70 ms 34896 KB Output is correct
10 Correct 71 ms 35164 KB Output is correct
11 Correct 69 ms 35244 KB Output is correct
12 Correct 68 ms 35080 KB Output is correct
13 Correct 74 ms 35156 KB Output is correct
14 Correct 72 ms 34900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 35024 KB Output is correct
2 Correct 46 ms 34848 KB Output is correct
3 Correct 376 ms 53856 KB Output is correct
4 Correct 678 ms 43444 KB Output is correct
5 Correct 509 ms 52920 KB Output is correct
6 Correct 501 ms 51276 KB Output is correct
7 Correct 538 ms 53940 KB Output is correct
8 Correct 832 ms 44368 KB Output is correct
9 Correct 401 ms 51388 KB Output is correct
10 Correct 232 ms 51180 KB Output is correct
11 Correct 178 ms 43272 KB Output is correct
12 Correct 523 ms 43708 KB Output is correct
13 Correct 735 ms 42720 KB Output is correct
14 Correct 681 ms 42936 KB Output is correct
15 Correct 345 ms 54128 KB Output is correct
16 Correct 311 ms 53060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 34900 KB Output is correct
2 Correct 673 ms 53692 KB Output is correct
3 Correct 690 ms 51652 KB Output is correct
4 Correct 201 ms 44960 KB Output is correct
5 Correct 704 ms 42684 KB Output is correct
6 Correct 678 ms 53604 KB Output is correct
7 Correct 342 ms 54176 KB Output is correct
8 Correct 336 ms 54596 KB Output is correct
9 Correct 322 ms 52808 KB Output is correct
10 Correct 567 ms 48360 KB Output is correct
11 Correct 581 ms 43836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 34904 KB Output is correct
2 Correct 487 ms 44980 KB Output is correct
3 Correct 441 ms 44144 KB Output is correct
4 Correct 493 ms 44232 KB Output is correct
5 Correct 203 ms 44216 KB Output is correct
6 Correct 204 ms 44032 KB Output is correct
7 Correct 491 ms 44216 KB Output is correct
8 Correct 305 ms 43720 KB Output is correct
9 Correct 254 ms 41652 KB Output is correct
10 Correct 846 ms 42936 KB Output is correct
11 Correct 581 ms 42916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 34888 KB Output is correct
2 Correct 67 ms 35060 KB Output is correct
3 Correct 50 ms 35036 KB Output is correct
4 Correct 69 ms 35156 KB Output is correct
5 Correct 68 ms 35164 KB Output is correct
6 Correct 65 ms 34896 KB Output is correct
7 Correct 67 ms 35152 KB Output is correct
8 Correct 72 ms 35412 KB Output is correct
9 Correct 70 ms 34896 KB Output is correct
10 Correct 71 ms 35164 KB Output is correct
11 Correct 69 ms 35244 KB Output is correct
12 Correct 68 ms 35080 KB Output is correct
13 Correct 74 ms 35156 KB Output is correct
14 Correct 72 ms 34900 KB Output is correct
15 Correct 67 ms 35024 KB Output is correct
16 Correct 46 ms 34848 KB Output is correct
17 Correct 376 ms 53856 KB Output is correct
18 Correct 678 ms 43444 KB Output is correct
19 Correct 509 ms 52920 KB Output is correct
20 Correct 501 ms 51276 KB Output is correct
21 Correct 538 ms 53940 KB Output is correct
22 Correct 832 ms 44368 KB Output is correct
23 Correct 401 ms 51388 KB Output is correct
24 Correct 232 ms 51180 KB Output is correct
25 Correct 178 ms 43272 KB Output is correct
26 Correct 523 ms 43708 KB Output is correct
27 Correct 735 ms 42720 KB Output is correct
28 Correct 681 ms 42936 KB Output is correct
29 Correct 345 ms 54128 KB Output is correct
30 Correct 311 ms 53060 KB Output is correct
31 Correct 45 ms 34900 KB Output is correct
32 Correct 673 ms 53692 KB Output is correct
33 Correct 690 ms 51652 KB Output is correct
34 Correct 201 ms 44960 KB Output is correct
35 Correct 704 ms 42684 KB Output is correct
36 Correct 678 ms 53604 KB Output is correct
37 Correct 342 ms 54176 KB Output is correct
38 Correct 336 ms 54596 KB Output is correct
39 Correct 322 ms 52808 KB Output is correct
40 Correct 567 ms 48360 KB Output is correct
41 Correct 581 ms 43836 KB Output is correct
42 Correct 48 ms 34904 KB Output is correct
43 Correct 487 ms 44980 KB Output is correct
44 Correct 441 ms 44144 KB Output is correct
45 Correct 493 ms 44232 KB Output is correct
46 Correct 203 ms 44216 KB Output is correct
47 Correct 204 ms 44032 KB Output is correct
48 Correct 491 ms 44216 KB Output is correct
49 Correct 305 ms 43720 KB Output is correct
50 Correct 254 ms 41652 KB Output is correct
51 Correct 846 ms 42936 KB Output is correct
52 Correct 581 ms 42916 KB Output is correct
53 Correct 63 ms 34900 KB Output is correct
54 Correct 66 ms 34900 KB Output is correct
55 Correct 45 ms 34948 KB Output is correct
56 Correct 71 ms 35436 KB Output is correct
57 Correct 66 ms 35164 KB Output is correct
58 Correct 64 ms 34896 KB Output is correct
59 Correct 67 ms 35200 KB Output is correct
60 Correct 67 ms 35352 KB Output is correct
61 Correct 81 ms 34928 KB Output is correct
62 Correct 69 ms 35156 KB Output is correct
63 Correct 69 ms 35152 KB Output is correct
64 Correct 65 ms 35164 KB Output is correct
65 Correct 71 ms 34924 KB Output is correct
66 Correct 74 ms 34936 KB Output is correct
67 Correct 355 ms 53684 KB Output is correct
68 Correct 646 ms 42964 KB Output is correct
69 Correct 511 ms 53084 KB Output is correct
70 Correct 546 ms 51824 KB Output is correct
71 Correct 535 ms 53712 KB Output is correct
72 Correct 853 ms 44708 KB Output is correct
73 Correct 368 ms 51384 KB Output is correct
74 Correct 226 ms 50624 KB Output is correct
75 Correct 175 ms 43188 KB Output is correct
76 Correct 517 ms 42940 KB Output is correct
77 Correct 723 ms 42936 KB Output is correct
78 Correct 688 ms 43056 KB Output is correct
79 Correct 336 ms 53684 KB Output is correct
80 Correct 311 ms 53176 KB Output is correct
81 Correct 691 ms 53696 KB Output is correct
82 Correct 676 ms 51316 KB Output is correct
83 Correct 209 ms 44908 KB Output is correct
84 Correct 743 ms 43704 KB Output is correct
85 Correct 701 ms 53612 KB Output is correct
86 Correct 343 ms 54560 KB Output is correct
87 Correct 334 ms 53644 KB Output is correct
88 Correct 641 ms 48708 KB Output is correct
89 Correct 576 ms 43452 KB Output is correct
90 Correct 476 ms 44456 KB Output is correct
91 Correct 464 ms 44240 KB Output is correct
92 Correct 460 ms 44232 KB Output is correct
93 Correct 202 ms 44984 KB Output is correct
94 Correct 206 ms 44296 KB Output is correct
95 Correct 493 ms 44780 KB Output is correct
96 Correct 302 ms 43588 KB Output is correct
97 Correct 254 ms 41652 KB Output is correct
98 Correct 865 ms 42904 KB Output is correct
99 Correct 582 ms 43320 KB Output is correct
100 Correct 151 ms 40480 KB Output is correct
101 Correct 702 ms 51528 KB Output is correct
102 Correct 187 ms 43960 KB Output is correct
103 Correct 515 ms 49756 KB Output is correct
104 Correct 650 ms 53428 KB Output is correct