제출 #1059333

#제출 시각아이디문제언어결과실행 시간메모리
1059333alexander707070즐거운 행로 (APIO20_fun)C++14
26 / 100
2070 ms16728 KiB
#include<bits/stdc++.h> #include "fun.h" #define MAXN 200007 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; for(int i=0;i<n-1;i++){ sort(subtrees.begin(),subtrees.end(),cmp); if(subtrees.size()==3 and subtrees[0].size()+subtrees[1].size()==subtrees[2].size()){ 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; }

컴파일 시 표준 에러 (stderr) 메시지

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:31: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]
   31 |         for(int f=0;f<subtrees.size();f++){
      |                     ~^~~~~~~~~~~~~~~~
fun.cpp:32: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]
   32 |             if(f==subtrees.size()-1){
      |                ~^~~~~~~~~~~~~~~~~~~
fun.cpp:45: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]
   45 |     for(int i=0;i<subtrees.size();i++){
      |                 ~^~~~~~~~~~~~~~~~
fun.cpp:67: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]
   67 |         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...