Submission #574131

#TimeUsernameProblemLanguageResultExecution timeMemory
574131eecsStranded Far From Home (BOI22_island)C++17
100 / 100
456 ms28296 KiB
#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 (stderr)

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;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...