Submission #934449

#TimeUsernameProblemLanguageResultExecution timeMemory
934449irmuunFun Tour (APIO20_fun)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> #include "fun.h" using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() vector<int>createFunTour(int N,int Q){ vector<int>adj[N]; for(int i=1;i<N;i++){ int p=(i-1)/2; adj[i].pb(p); adj[p].pb(i); } set<pair<int,int>,greater<pair<int,int>>>st[N]; for(int i=0;i<N;i++){ int cur=i,dist=0; while(true){ if(cur<i){ st[cur].insert({dist,i}); } if(cur==0) break; cur=(cur-1)/2; dist++; } } auto [z,s]=*st[0].begin(); vector<int>ans={s}; int cur=s,bef=-1; for(int i=2;i<=N;i++){ int dist=0; cur=s; while(true){ if(cur<s){ st[cur].erase({dist,s}); } if(cur==0) break; cur=(cur-1)/2; dist++; } int mx=-1,nxt=-1,add=1; cur=s; while(true){ if(cur<s){ for(auto u:adj[cur]){ if(u<cur||u==bef) continue; ll D,j; if(st[u].size()>0){ auto p=*st[u].begin(); D=p.ff; j=p.ss; } else{ D=0; j=u; } D+=add; if(D>mx){ mx=D; nxt=j; } } } add++; if(cur==0) break; bef=cur; cur=(cur-1)/2; } ans.pb(nxt); s=nxt; } ans.back()=0; 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...