Submission #574132

# Submission time Handle Problem Language Result Execution time Memory
574132 2022-06-08T01:54:39 Z eecs Stranded Far From Home (BOI22_island) C++17
100 / 100
320 ms 30880 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], Q[maxn];

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);
    }
    sort(V.begin(), V.end());
    for (int i = 1; i <= n; i++) {
        int j = lower_bound(V.begin(), V.end(), array<int, 2>{a[i] + 1, 0}) - V.begin() - 1;
        Q[j].push_back(i);
    }
    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;
        for (int x : Q[i]) {
            int y = lower_bound(V.begin(), V.end(), array<int, 2>{sum[find(x)] + 1, 0}) - V.begin() - 1;
            if (i < y) Q[y].push_back(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:43: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]
   43 |             else if (i + 1 == V.size()) ans[x] = 1;
      |                      ~~~~~~^~~~~~~~~~~
island.cpp:32:9: warning: unused variable 'lst' [-Wunused-variable]
   32 |     int lst = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9740 KB Output is correct
3 Correct 7 ms 9644 KB Output is correct
4 Correct 6 ms 9788 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 6 ms 9820 KB Output is correct
7 Correct 7 ms 9884 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9824 KB Output is correct
10 Correct 7 ms 9824 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 8 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 178 ms 28532 KB Output is correct
4 Correct 150 ms 23104 KB Output is correct
5 Correct 209 ms 27168 KB Output is correct
6 Correct 208 ms 26392 KB Output is correct
7 Correct 196 ms 27700 KB Output is correct
8 Correct 204 ms 23104 KB Output is correct
9 Correct 166 ms 26264 KB Output is correct
10 Correct 151 ms 26016 KB Output is correct
11 Correct 160 ms 25396 KB Output is correct
12 Correct 152 ms 22076 KB Output is correct
13 Correct 133 ms 24320 KB Output is correct
14 Correct 143 ms 24184 KB Output is correct
15 Correct 162 ms 28480 KB Output is correct
16 Correct 116 ms 28480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9660 KB Output is correct
2 Correct 300 ms 27528 KB Output is correct
3 Correct 259 ms 26328 KB Output is correct
4 Correct 166 ms 24604 KB Output is correct
5 Correct 132 ms 23696 KB Output is correct
6 Correct 266 ms 27716 KB Output is correct
7 Correct 179 ms 30864 KB Output is correct
8 Correct 210 ms 30812 KB Output is correct
9 Correct 124 ms 28504 KB Output is correct
10 Correct 155 ms 25980 KB Output is correct
11 Correct 159 ms 22968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9664 KB Output is correct
2 Correct 198 ms 22364 KB Output is correct
3 Correct 176 ms 22472 KB Output is correct
4 Correct 187 ms 22544 KB Output is correct
5 Correct 186 ms 22204 KB Output is correct
6 Correct 149 ms 21752 KB Output is correct
7 Correct 135 ms 25248 KB Output is correct
8 Correct 102 ms 23184 KB Output is correct
9 Correct 112 ms 17072 KB Output is correct
10 Correct 160 ms 22084 KB Output is correct
11 Correct 167 ms 23300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9740 KB Output is correct
3 Correct 7 ms 9644 KB Output is correct
4 Correct 6 ms 9788 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 6 ms 9820 KB Output is correct
7 Correct 7 ms 9884 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9824 KB Output is correct
10 Correct 7 ms 9824 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 7 ms 9812 KB Output is correct
13 Correct 8 ms 9812 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 178 ms 28532 KB Output is correct
18 Correct 150 ms 23104 KB Output is correct
19 Correct 209 ms 27168 KB Output is correct
20 Correct 208 ms 26392 KB Output is correct
21 Correct 196 ms 27700 KB Output is correct
22 Correct 204 ms 23104 KB Output is correct
23 Correct 166 ms 26264 KB Output is correct
24 Correct 151 ms 26016 KB Output is correct
25 Correct 160 ms 25396 KB Output is correct
26 Correct 152 ms 22076 KB Output is correct
27 Correct 133 ms 24320 KB Output is correct
28 Correct 143 ms 24184 KB Output is correct
29 Correct 162 ms 28480 KB Output is correct
30 Correct 116 ms 28480 KB Output is correct
31 Correct 5 ms 9660 KB Output is correct
32 Correct 300 ms 27528 KB Output is correct
33 Correct 259 ms 26328 KB Output is correct
34 Correct 166 ms 24604 KB Output is correct
35 Correct 132 ms 23696 KB Output is correct
36 Correct 266 ms 27716 KB Output is correct
37 Correct 179 ms 30864 KB Output is correct
38 Correct 210 ms 30812 KB Output is correct
39 Correct 124 ms 28504 KB Output is correct
40 Correct 155 ms 25980 KB Output is correct
41 Correct 159 ms 22968 KB Output is correct
42 Correct 6 ms 9664 KB Output is correct
43 Correct 198 ms 22364 KB Output is correct
44 Correct 176 ms 22472 KB Output is correct
45 Correct 187 ms 22544 KB Output is correct
46 Correct 186 ms 22204 KB Output is correct
47 Correct 149 ms 21752 KB Output is correct
48 Correct 135 ms 25248 KB Output is correct
49 Correct 102 ms 23184 KB Output is correct
50 Correct 112 ms 17072 KB Output is correct
51 Correct 160 ms 22084 KB Output is correct
52 Correct 167 ms 23300 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9684 KB Output is correct
56 Correct 6 ms 9812 KB Output is correct
57 Correct 7 ms 9908 KB Output is correct
58 Correct 6 ms 9812 KB Output is correct
59 Correct 7 ms 9924 KB Output is correct
60 Correct 6 ms 9812 KB Output is correct
61 Correct 6 ms 9812 KB Output is correct
62 Correct 7 ms 9812 KB Output is correct
63 Correct 7 ms 9812 KB Output is correct
64 Correct 9 ms 9812 KB Output is correct
65 Correct 6 ms 9812 KB Output is correct
66 Correct 8 ms 9812 KB Output is correct
67 Correct 193 ms 28300 KB Output is correct
68 Correct 135 ms 23116 KB Output is correct
69 Correct 255 ms 27140 KB Output is correct
70 Correct 192 ms 26296 KB Output is correct
71 Correct 238 ms 27672 KB Output is correct
72 Correct 183 ms 23032 KB Output is correct
73 Correct 163 ms 26144 KB Output is correct
74 Correct 153 ms 26020 KB Output is correct
75 Correct 157 ms 25408 KB Output is correct
76 Correct 164 ms 22232 KB Output is correct
77 Correct 131 ms 24360 KB Output is correct
78 Correct 167 ms 24220 KB Output is correct
79 Correct 163 ms 28448 KB Output is correct
80 Correct 119 ms 28472 KB Output is correct
81 Correct 300 ms 27540 KB Output is correct
82 Correct 271 ms 26352 KB Output is correct
83 Correct 187 ms 24672 KB Output is correct
84 Correct 142 ms 23600 KB Output is correct
85 Correct 279 ms 27640 KB Output is correct
86 Correct 182 ms 30880 KB Output is correct
87 Correct 230 ms 30784 KB Output is correct
88 Correct 160 ms 25992 KB Output is correct
89 Correct 163 ms 23028 KB Output is correct
90 Correct 215 ms 22320 KB Output is correct
91 Correct 182 ms 22468 KB Output is correct
92 Correct 191 ms 22628 KB Output is correct
93 Correct 186 ms 22224 KB Output is correct
94 Correct 158 ms 21744 KB Output is correct
95 Correct 131 ms 25124 KB Output is correct
96 Correct 104 ms 23204 KB Output is correct
97 Correct 106 ms 17100 KB Output is correct
98 Correct 160 ms 22080 KB Output is correct
99 Correct 192 ms 23336 KB Output is correct
100 Correct 49 ms 12108 KB Output is correct
101 Correct 287 ms 26456 KB Output is correct
102 Correct 156 ms 19864 KB Output is correct
103 Correct 231 ms 23888 KB Output is correct
104 Correct 320 ms 27320 KB Output is correct