Submission #934451

#TimeUsernameProblemLanguageResultExecution timeMemory
934451irmuunFun Tour (APIO20_fun)C++17
0 / 100
0 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){ ll D,j; if(st[cur].size()==0){ D=0; j=cur; D+=add-1; } else{ for(auto u:adj[cur]){ if(u<cur||u==bef) continue; if(st[u].size()>0){ auto p=*st[u].begin(); D=p.ff; j=p.ss; D+=add; } else{ D=0; j=u; D+=add-1; } break; } } if(D>mx){ mx=D; nxt=j; } } add++; if(cur==0) break; bef=cur; cur=(cur-1)/2; } ans.pb(nxt); s=nxt; } return ans; }

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:75:24: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |                     nxt=j;
      |                     ~~~^~
fun.cpp:74:23: warning: 'D' may be used uninitialized in this function [-Wmaybe-uninitialized]
   74 |                     mx=D;
      |                     ~~^~
#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...