Submission #786309

#TimeUsernameProblemLanguageResultExecution timeMemory
786309vjudge1Thousands Islands (IOI22_islands)C++17
39.40 / 100
44 ms6096 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { if (N == 2) { vector<int> f0, f1; for (int i = 0; i < M; i++) { (U[i] == 0 ? f0 : f1).push_back(i); } if (f0.size() < 2 || f1.size() < 1) { return false; } return vector{f0[0], f1[0], f0[1], f0[0], f1[0], f0[1]}; } bool S3 = M % 2 == 0; bool S4 = M % 2 == 0; vector<vector<pair<int, int>>> adj(N); for (int i = 0; i < M; i++) { if (i % 2 == 1 && (U[i - 1] != V[i] || V[i - 1] != U[i])) { S3 = 0; } if (i % 2 == 1 && (U[i - 1] != U[i] || V[i - 1] != V[i])) { S4 = 0; } adj[U[i]].emplace_back(V[i], i); } if (S3) { int x = 0, y = -1; vector<int> p; while (1) { if (adj[x].size() < 2 - (y == -1)) { return false; } if (adj[x].size() > 2 - (y == -1)) { auto ans = p; int u, v; if (y == -1) { u = adj[x][0].second; v = adj[x][1].second; } else { u = adj[x][adj[x][0].second == (y ^ 1) ? 1 : 0].second; v = adj[x][adj[x][2].second == (y ^ 1) ? 1 : 2].second; } ans.push_back(u); ans.push_back(u ^ 1); ans.push_back(v); ans.push_back(v ^ 1); ans.push_back(u ^ 1); ans.push_back(u); ans.push_back(v ^ 1); ans.push_back(v); for (int i = p.size() - 1; i >= 0; i--) { ans.push_back(p[i]); } return ans; } if (adj[x][0].second == (y ^ 1)) { tie(x, y) = adj[x][1]; } else { tie(x, y) = adj[x][0]; } p.push_back(y); } } if (S4) { vector<int> vis(N), p, ans; auto dfs = [&](auto dfs, int x) -> bool { vis[x] = 1; for (auto [y, z] : adj[x]) { if (vis[y] == 1) { p.push_back(z); vector<int> c; int u = y; while (1) { int t = p.back(); p.pop_back(); c.push_back(t); u ^= U[t] ^ V[t]; if (u == y) { break; } } ans = p; for (int i = c.size() - 1; i >= 0; i--) { ans.push_back(c[i]); } for (int i = c.size() - 1; i >= 0; i--) { ans.push_back(c[i] ^ 1); } for (int i = 0; i < c.size(); i++) { ans.push_back(c[i] ^ 1); } for (int i = 0; i < c.size(); i++) { ans.push_back(c[i]); } for (int i = p.size() - 1; i >= 0; i--) { ans.push_back(p[i]); } return 1; } if (!vis[y]) { p.push_back(z); if (dfs(dfs, y)) { return 1; } p.pop_back(); } } vis[x] = 2; return 0; }; if (dfs(dfs, 0)) { return ans; } else { return false; } } int a, b, c, d; for (int i = 0; i < M; i++) { if (U[i] == 0) { if (V[i] == 1) { a = i; } if (V[i] == 2) { c = i; } } if (V[i] == 0) { if (U[i] == 1) { b = i; } if (U[i] == 2) { d = i; } } } return vector{a, b, c, d, b, a, d, c}; }

Compilation message (stderr)

islands.cpp: In lambda function:
islands.cpp:90:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |                     for (int i = 0; i < c.size(); i++) {
      |                                     ~~^~~~~~~~~~
islands.cpp:93:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                     for (int i = 0; i < c.size(); i++) {
      |                                     ~~^~~~~~~~~~
islands.cpp: In instantiation of 'find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)> [with auto:23 = find_journey(int, int, std::vector<int>, std::vector<int>)::<lambda(auto:23, int)>]':
islands.cpp:112:23:   required from here
islands.cpp:90:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |                     for (int i = 0; i < c.size(); i++) {
      |                                     ~~^~~~~~~~~~
islands.cpp:93:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                     for (int i = 0; i < c.size(); i++) {
      |                                     ~~^~~~~~~~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:137:41: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
  137 |     return vector{a, b, c, d, b, a, d, c};
      |                                         ^
islands.cpp:137:41: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:137:41: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:137:41: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...