Submission #1069629

#TimeUsernameProblemLanguageResultExecution timeMemory
1069629ewirlanThousands Islands (IOI22_islands)C++17
100 / 100
102 ms19492 KiB
// #ifndef __SIZEOF_INT128__ #define __SIZEOF_INT128__ #endif #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define rep(i, p, k) for(int i(p); i < (k); ++i) #define per(i, p, k) for(int i(p); i > (k); --i) #define sz(x) (int)(x).size() #define sc static_cast typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef __int128_t lll; //#define int ll template <typename T = int> using par = std::pair <T, T>; #define fi first #define se second #define test int _number_of_tests(in()); while(_number_of_tests--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb emplace_back struct Timer { string name{""}; time_point<high_resolution_clock> end, start{high_resolution_clock::now()}; duration<float, std::milli> dur; Timer() = default; Timer(string nm): name(nm) {} ~Timer() { end = high_resolution_clock::now(); dur= end - start; cout << "@" << name << "> " << dur.count() << " ms" << '\n'; } }; template <typename T = int> inline T in() { static T x; std::cin >> x; return x; } std::string yn(bool b) { if(b) return "YES\n"; else return "NO\n"; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par); template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek) { for(const auto& i : wek)out << i << ' '; return out; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par) { out << '{'<<par.first<<", "<<par.second<<"}"; return out; } #define show(x) cerr << #x << " = " << x << '\n'; constexpr int maxn = 1e5 + 3; vector <pair <int, int>> graf[maxn]; vector <pair <int, int>> rgraf[maxn]; bool us[maxn]; int sto[maxn]; void del(int w){ if(us[w])return; us[w] = 1; for(auto [i, j]: rgraf[w])if(!--sto[i])del(i); } pair <int, int> ns[maxn]; bool byla[maxn], bylb[maxn], wcyk[maxn]; variant <bool, vector <int>> find_journey(int n, int m, vector <int> u, vector <int> v){ rep(i, 0, m){ graf[u[i]].pb(v[i], i); rgraf[v[i]].pb(u[i], i); } rep(i, 0, n)sto[i] = sz(graf[i]); int s(0); vector <int> ds; rep(i, 0, n)if(!sto[i])del(i); while(!us[s] && sto[s] == 1){ del(s); for(auto [i, j]: graf[s])if(!us[i]){ ds.pb(j); s = i; break; } } if(us[s])return false; vector <pair <int, int>> hh; for(auto i: graf[s])if(!us[i.first])hh.pb(i); assert(sz(hh) >= 2); auto a(hh[0]), b(hh[1]); rep(w, 0, n)if(!us[w] && w != s)for(auto [i, j]: graf[w])if(!us[i] && w != i){ ns[w] = {i,j}; break; } vector <int> cykl, edc; vector <pair <int, int>> dc{a}, db{{s, 0}, b}; byla[s] = bylb[s] = 1; while(!byla[dc.back().first]){ // cerr << dc.back() << ' '; byla[dc.back().first] = 1; dc.pb(ns[dc.back().first]); } // cerr << '\n'; while(dc.size() && !wcyk[dc.back().first]){ cykl.pb(dc.back().first); edc.pb(dc.back().second); wcyk[dc.back().first] = 1; dc.pop_back(); } // cerr << cykl << " : " << edc << '\n'; while(!bylb[db.back().first] && !wcyk[db.back().first]){ bylb[db.back().first] = 1; db.pb(ns[db.back().first]); } vector <int> rt; for(auto i: ds)rt.pb(i); reverse(all(dc)); rep(xd, 0, 2){ reverse(all(dc)); for(auto i: dc)rt.pb(i.second); reverse(all(edc)); for(auto i: edc)rt.pb(i); reverse(all(dc)); for(auto i: dc)rt.pb(i.second); if(wcyk[db.back().first]){ rep(i, 1, sz(db))rt.pb(db[i].second); reverse(all(edc)); rep(i, 0, sz(cykl))if(cykl[i] == db.back().first){ rep(j, 0, sz(edc))rt.pb(edc[(i+j) % sz(edc)]); reverse(all(db)); for(auto i: db)rt.pb(i.second); rt.pop_back(); reverse(all(db)); break; } } else{ per(i, sz(db)-2, -1)if(db[i].first == db.back().first){ rep(j, 1, i+1)rt.pb(db[j].second); if(xd % 2 == 0)rep(j, i+1, sz(db))rt.pb(db[j].second); else per(j, sz(db)-1, i)rt.pb(db[j].second); per(j, i, 0)rt.pb(db[j].second); } } } reverse(all(ds)); for(auto i: ds)rt.pb(i); return rt; }
#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...