제출 #1034629

#제출 시각아이디문제언어결과실행 시간메모리
1034629Mr_Husanboy수천개의 섬 (IOI22_islands)C++17
27.75 / 100
21 ms5468 KiB
#include "islands.h" #include <variant> #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) (a).begin(), (a).end() #define ll long long const int mod = 1000002022; vector<int> state, p; int n, m; vector<vector<int>> g; template<typename T> int len(T &a){return a.size();} mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); variant<bool, vector<int>> find_journey( int n, int m, std::vector<int> u, std::vector<int> v) { vector<vector<int>> g(n); for(int i = 0; i < m; i ++) g[u[i]].push_back(i); if(len(g[0]) == 0) return false; if(n == 2){ if(len(g[0]) <= 1) return false; if(len(g[1]) == 0) return false; return vector {g[0][0], g[1][0], g[0][1], g[0][0], g[1][0], g[0][1]}; } if(len(g[0]) == 2){ int a = g[0][0], b = g[0][1]; return vector{a, a ^ 1, b, b ^ 1, a ^ 1, a, b ^ 1, b}; } vector<int> ans = {g[0][0]}; int cnt = 0; vector<int> cyc; while(true){ int cur = v[ans.back()]; cnt ++; if(len(g[cur]) <= 1){ return false; } if(len(g[cur]) >= 3){ vector<int> v; for(int j = 0; j < 3; j ++) if(g[cur][j] != (ans.back() ^ 1)) v.push_back(g[cur][j]); int a = v[0], b = v[1]; cyc = vector{a, a ^ 1, b, b ^ 1, a ^ 1, a, b ^ 1, b}; break; } if(g[cur][0] == (ans.back() ^ 1)){ ans.push_back(g[cur][1]); }else ans.push_back(g[cur][0]); } vector<int> res = ans; for(auto u : cyc) res.push_back(u); reverse(all(ans)); for(auto u : ans) res.push_back(u); return res; }
#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...