Submission #576668

#TimeUsernameProblemLanguageResultExecution timeMemory
576668radalFun Tour (APIO20_fun)C++17
26 / 100
89 ms32648 KiB
#include "fun.h" #include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse4,avx2") #pragma GCC optimize("unroll-loops,O2") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define all(x) (x).begin() , (x).end() #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pll; constexpr int N = 2e5+20,mod = 998244353,inf = 1e9+10; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; // if (a+b < 0) return a+b+mod; return a+b; } vector<int> adj[N]; int n,h[N],vis[N],T,tin[N],tout[N]; void dfs(int v,int p){ tin[v] = T; T++; for (int u : adj[v]){ if (u != p){ h[u] = h[v]+1; dfs(u,v); } } tout[v] = T; T++; } vector<int> createFunTour(int N, int Q){ n = N; if (1ll*n*(n-1)/2 <= Q){ rep(i,0,n){ rep(j,i+1,n) if (hoursRequired(i,j) == 1){ adj[i].pb(j); adj[j].pb(i); } } } else{ rep(i,1,n){ adj[(i-1)/2].pb(i); adj[i].pb((i-1)/2); } dfs(0,-1); set<pll> st1,st2; rep(i,0,n){ st1.insert({-tin[i],i}); st2.insert({tout[i],i}); } bool f = 0; vector<int> ans(n); rep(i,0,n){ if (f){ pll p = *(st1.begin()); st1.erase(p); st2.erase({tout[p.Y],p.Y}); ans[i] = p.Y; f = !f; continue; } else{ pll p = *(st2.begin()); st2.erase(p); st1.erase({-tin[p.Y],p.Y}); ans[i] = p.Y; f = !f; continue; } } return ans; } vector<int> ans; ans.resize(n); int cur = 0; rep(i,0,n){ h[cur] = 0; dfs(cur,-1); int mx = 0,ind = -1; rep(j,0,n){ if (!vis[j] && h[j] > mx){ ind = j; mx = h[j]; } } vis[ind] = 1; ans[i] = ind; cur = ind; } return ans; }
#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...