Submission #1059351

#TimeUsernameProblemLanguageResultExecution timeMemory
1059351alexander707070Fun Tour (APIO20_fun)C++14
66 / 100
139 ms38348 KiB
#include<bits/stdc++.h> #include "fun.h" #define MAXN 100007 using namespace std; int n,centroid,sz[MAXN],dist[MAXN],curr; vector< vector< pair<int,int> > > subtrees; int best,last; vector<int> perm; bool cmp(vector< pair<int,int> > fr,vector< pair<int,int> > sc){ return fr.size()<sc.size(); } vector<int> createFunTour(int N, int Q){ n=N; for(int i=0;i<n;i++){ sz[i]=attractionsBehind(0,i); if(sz[i]>n/2 and sz[i]<sz[centroid])centroid=i; } for(int i=0;i<n;i++){ dist[i]=hoursRequired(centroid,i); if(dist[i]==1)subtrees.push_back({{1,i}}); } for(int i=0;i<n;i++){ if(dist[i]<=1)continue; for(int f=0;f<subtrees.size();f++){ if(f==subtrees.size()-1){ subtrees.back().push_back({dist[i],i}); break; } curr=hoursRequired(subtrees[f][0].second,i); if(curr+1==dist[i]){ subtrees[f].push_back({dist[i],i}); break; } } } for(int i=0;i<subtrees.size();i++){ sort(subtrees[i].begin(),subtrees[i].end()); } last=-1; if(subtrees.size()==2){ if(subtrees[0].size()<=subtrees[1].size() and !subtrees[0].empty())last=subtrees[0][0].second; else last=subtrees[1][0].second; } for(int i=0;i<n-1;i++){ int maxs=0,sum=0; for(int f=0;f<subtrees.size();f++){ maxs=max(maxs,int(subtrees[f].size())); sum+=subtrees[f].size(); } if(subtrees.size()==3 and maxs*2==sum){ sort(subtrees.begin(),subtrees.end(),cmp); for(pair<int,int> i:subtrees[1])subtrees[0].push_back(i); sort(subtrees[0].begin(),subtrees[0].end()); if(!subtrees[1].empty() and last==subtrees[1][0].second){ last=subtrees[0][0].second; } subtrees[1]=subtrees[2]; subtrees.pop_back(); } int best=-1; for(int f=0;f<subtrees.size();f++){ if(subtrees[f].empty() or last==subtrees[f][0].second)continue; if(best==-1 or subtrees[f].back().first>subtrees[best].back().first)best=f; if(subtrees[f].back().first==subtrees[best].back().first and subtrees[f].size()>subtrees[best].size())best=f; } perm.push_back(subtrees[best].back().second); last=subtrees[best][0].second; subtrees[best].pop_back(); } perm.push_back(centroid); return perm; }

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int f=0;f<subtrees.size();f++){
      |                     ~^~~~~~~~~~~~~~~~
fun.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             if(f==subtrees.size()-1){
      |                ~^~~~~~~~~~~~~~~~~~~
fun.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<subtrees.size();i++){
      |                 ~^~~~~~~~~~~~~~~~
fun.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int f=0;f<subtrees.size();f++){
      |                     ~^~~~~~~~~~~~~~~~
fun.cpp:81:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int f=0;f<subtrees.size();f++){
      |                     ~^~~~~~~~~~~~~~~~
#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...