제출 #1085731

#제출 시각아이디문제언어결과실행 시간메모리
1085731SamueleVid수천개의 섬 (IOI22_islands)C++17
10 / 100
23 ms6740 KiB
#include <bits/stdc++.h> using namespace std; // constexpr int MAXN = 1e5 + 5; constexpr int MAXN = 1e3 + 5; constexpr int MAXM = 2e5 + 5; vector<array<int, 3>> adj_barche[MAXN]; // adj[U[i]] {nodo, barca, barca di ritorno} // vector<int> adj[MAXN]; bool v[MAXN]; vector<int> barche; vector<int> res_barche; variant<bool, vector<int>> n_two(int N, int M, vector<int> U, vector<int> V) { vector<int> el_primo; vector<int> el_secondo; for (int i = 0; i < M; i ++) { if (U[i] == 0) el_primo.push_back(i); if (U[i] == 1) el_secondo.push_back(i); } if (el_primo.size() >= 2 && el_secondo.size() >= 1) { int a = el_primo[0]; int b = el_secondo[0]; int c = el_primo[1]; vector<int> res = {a, b, c, a, b, c}; return res; } return false; } variant<bool, vector<int>> subtask_two(int N, int M, vector<int> U, vector<int> V) { int a, b, c, d, e, f; for (int i = 0; i < M; i ++) { if (U[i] == 0 && V[i] == 1) a = i; if (U[i] == 1 && V[i] == 0) b = i; if (U[i] == 1 && V[i] == 2) c = i; if (U[i] == 2 && V[i] == 1) d = i; if (U[i] == 2 && V[i] == 0) e = i; if (U[i] == 0 && V[i] == 2) f = i; } vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f}; return res; } void dfs(int u, int prev_barca) { // cout << "u, prev_barca : " << u << " " << (char)(prev_barca + 'A') << '\n'; if (adj_barche[u].size() >= 2 + (prev_barca != -1)) { // cout << "ce ne sono due !!" << '\n'; vector<int> barche_prese; for (auto [x, b_u, b_v] : adj_barche[u]) { if (b_u == prev_barca) continue; // non succede mai tho barche_prese.push_back(b_u); barche_prese.push_back(b_v); if (barche_prese.size() == 4) break; } int c = barche_prese[0]; int d = barche_prese[1]; int e = barche_prese[2]; int f = barche_prese[3]; vector<int> nuovo = {c, d, e, f, d, c, f, e}; vector<int> old_barche = barche; reverse(old_barche.begin(), old_barche.end()); for (auto x : nuovo) barche.push_back(x); for (auto x : old_barche) barche.push_back(x); res_barche = barche; return; } for (auto [x, b_u, b_v] : adj_barche[u]) { if (b_u == prev_barca) continue; // non succede mai tho barche.push_back(b_u); // cout << "vado verso " << x << '\n'; dfs(x, b_v); if (res_barche.size()) return; barche.pop_back(); } } variant<bool, vector<int>> subtask_tre(int N, int M, vector<int> U, vector<int> V) { fill(v, v + MAXN, 0); for (int i = 0; i < M; i ++) { adj_barche[U[i]].push_back({V[i], i, i ^ 1}); } dfs(0, -1); if (!res_barche.size()) return false; return res_barche; } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { if (N <= 2) return n_two(N, M, U, V); bool flag_subtask_tre = false; for (int i = 0; i < M; i += 2) { if (!(U[i] == V[i + 1] && V[i] == U[i + 1])) flag_subtask_tre = false; } if (flag_subtask_tre) return subtask_tre(N, M, U, V); if (N <= 400) return subtask_two(N, M, U, V); }

컴파일 시 표준 에러 (stderr) 메시지

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:109:1: warning: control reaches end of non-void function [-Wreturn-type]
  109 | }
      | ^
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > subtask_two(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:44:58: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
      |                                                          ^
islands.cpp:44:58: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: 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...