답안 #574131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574131 2022-06-08T01:51:59 Z eecs Stranded Far From Home (BOI22_island) C++17
100 / 100
456 ms 28296 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 200010;
int n, m, a[maxn], fa[maxn], sum[maxn];
bool vis[maxn], ans[maxn];
vector<int> G[maxn];
set<pair<int, int>> S;

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m;
    vector<array<int, 2>> V;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], V.push_back({a[i], i});
    }
    while (m--) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v), G[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        S.emplace(a[i], i);
    }
    sort(V.begin(), V.end());
    iota(fa + 1, fa + n + 1, 1);
    copy(a + 1, a + n + 1, sum + 1);
    int lst = 0;
    for (int i = 0; i < V.size(); i++) {
        vis[V[i][1]] = 1;
        for (int j : G[V[i][1]]) if (vis[j]) {
            int x = find(V[i][1]), y = find(j);
            if (x ^ y) fa[y] = x, sum[x] = min((int)1e9, sum[x] + sum[y]);
        }
        if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue;
        while (!S.empty() && V[i][0] == S.begin()->first) {
            int x = S.begin()->second;
            int y = prev(lower_bound(V.begin(), V.end(), array<int, 2>{sum[find(x)] + 1, 0}))->at(0);
            S.erase(S.begin());
            if (V[i][0] < y) S.emplace(y, x);
            else if (i + 1 == V.size()) ans[x] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << (ans[i] ? '1' : '0');
    }
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < V.size(); i++) {
      |                     ~~^~~~~~~~~~
island.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue;
      |             ~~~~~~^~~~~~~~~~
island.cpp:45:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             else if (i + 1 == V.size()) ans[x] = 1;
      |                      ~~~~~~^~~~~~~~~~~
island.cpp:32:9: warning: unused variable 'lst' [-Wunused-variable]
   32 |     int lst = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5244 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 6 ms 5204 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 4 ms 5244 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 226 ms 25296 KB Output is correct
4 Correct 204 ms 26048 KB Output is correct
5 Correct 260 ms 24468 KB Output is correct
6 Correct 301 ms 25076 KB Output is correct
7 Correct 276 ms 25108 KB Output is correct
8 Correct 282 ms 25240 KB Output is correct
9 Correct 197 ms 25024 KB Output is correct
10 Correct 157 ms 25760 KB Output is correct
11 Correct 208 ms 28264 KB Output is correct
12 Correct 208 ms 25024 KB Output is correct
13 Correct 168 ms 27328 KB Output is correct
14 Correct 191 ms 27072 KB Output is correct
15 Correct 229 ms 25068 KB Output is correct
16 Correct 185 ms 24944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 414 ms 25072 KB Output is correct
3 Correct 456 ms 25120 KB Output is correct
4 Correct 206 ms 27528 KB Output is correct
5 Correct 189 ms 26532 KB Output is correct
6 Correct 380 ms 25168 KB Output is correct
7 Correct 273 ms 25208 KB Output is correct
8 Correct 235 ms 25096 KB Output is correct
9 Correct 188 ms 24944 KB Output is correct
10 Correct 248 ms 26316 KB Output is correct
11 Correct 205 ms 25332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 259 ms 25152 KB Output is correct
3 Correct 284 ms 25024 KB Output is correct
4 Correct 259 ms 25308 KB Output is correct
5 Correct 249 ms 25076 KB Output is correct
6 Correct 193 ms 24224 KB Output is correct
7 Correct 211 ms 26688 KB Output is correct
8 Correct 180 ms 26168 KB Output is correct
9 Correct 144 ms 16044 KB Output is correct
10 Correct 201 ms 25020 KB Output is correct
11 Correct 207 ms 25340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5244 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 6 ms 5204 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 4 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 4 ms 5244 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 4 ms 5204 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 3 ms 5016 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 226 ms 25296 KB Output is correct
18 Correct 204 ms 26048 KB Output is correct
19 Correct 260 ms 24468 KB Output is correct
20 Correct 301 ms 25076 KB Output is correct
21 Correct 276 ms 25108 KB Output is correct
22 Correct 282 ms 25240 KB Output is correct
23 Correct 197 ms 25024 KB Output is correct
24 Correct 157 ms 25760 KB Output is correct
25 Correct 208 ms 28264 KB Output is correct
26 Correct 208 ms 25024 KB Output is correct
27 Correct 168 ms 27328 KB Output is correct
28 Correct 191 ms 27072 KB Output is correct
29 Correct 229 ms 25068 KB Output is correct
30 Correct 185 ms 24944 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 414 ms 25072 KB Output is correct
33 Correct 456 ms 25120 KB Output is correct
34 Correct 206 ms 27528 KB Output is correct
35 Correct 189 ms 26532 KB Output is correct
36 Correct 380 ms 25168 KB Output is correct
37 Correct 273 ms 25208 KB Output is correct
38 Correct 235 ms 25096 KB Output is correct
39 Correct 188 ms 24944 KB Output is correct
40 Correct 248 ms 26316 KB Output is correct
41 Correct 205 ms 25332 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 259 ms 25152 KB Output is correct
44 Correct 284 ms 25024 KB Output is correct
45 Correct 259 ms 25308 KB Output is correct
46 Correct 249 ms 25076 KB Output is correct
47 Correct 193 ms 24224 KB Output is correct
48 Correct 211 ms 26688 KB Output is correct
49 Correct 180 ms 26168 KB Output is correct
50 Correct 144 ms 16044 KB Output is correct
51 Correct 201 ms 25020 KB Output is correct
52 Correct 207 ms 25340 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 4 ms 5204 KB Output is correct
57 Correct 5 ms 5204 KB Output is correct
58 Correct 4 ms 5204 KB Output is correct
59 Correct 4 ms 5204 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 4 ms 5204 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5204 KB Output is correct
64 Correct 4 ms 5204 KB Output is correct
65 Correct 4 ms 5204 KB Output is correct
66 Correct 5 ms 5204 KB Output is correct
67 Correct 259 ms 25120 KB Output is correct
68 Correct 174 ms 25916 KB Output is correct
69 Correct 260 ms 24456 KB Output is correct
70 Correct 250 ms 25116 KB Output is correct
71 Correct 269 ms 25144 KB Output is correct
72 Correct 267 ms 25204 KB Output is correct
73 Correct 187 ms 25036 KB Output is correct
74 Correct 167 ms 25716 KB Output is correct
75 Correct 191 ms 28296 KB Output is correct
76 Correct 196 ms 25088 KB Output is correct
77 Correct 195 ms 27300 KB Output is correct
78 Correct 180 ms 27148 KB Output is correct
79 Correct 229 ms 25172 KB Output is correct
80 Correct 189 ms 24912 KB Output is correct
81 Correct 369 ms 25004 KB Output is correct
82 Correct 383 ms 25208 KB Output is correct
83 Correct 199 ms 27492 KB Output is correct
84 Correct 178 ms 26504 KB Output is correct
85 Correct 376 ms 25168 KB Output is correct
86 Correct 252 ms 25140 KB Output is correct
87 Correct 243 ms 25236 KB Output is correct
88 Correct 220 ms 26336 KB Output is correct
89 Correct 221 ms 25308 KB Output is correct
90 Correct 267 ms 25080 KB Output is correct
91 Correct 250 ms 25032 KB Output is correct
92 Correct 250 ms 25112 KB Output is correct
93 Correct 226 ms 25104 KB Output is correct
94 Correct 214 ms 24232 KB Output is correct
95 Correct 204 ms 26752 KB Output is correct
96 Correct 175 ms 26300 KB Output is correct
97 Correct 145 ms 16092 KB Output is correct
98 Correct 190 ms 24932 KB Output is correct
99 Correct 215 ms 25368 KB Output is correct
100 Correct 43 ms 7416 KB Output is correct
101 Correct 373 ms 25108 KB Output is correct
102 Correct 194 ms 20856 KB Output is correct
103 Correct 337 ms 21924 KB Output is correct
104 Correct 419 ms 24700 KB Output is correct