제출 #434749

#제출 시각아이디문제언어결과실행 시간메모리
434749dqhungdl즐거운 행로 (APIO20_fun)C++17
0 / 100
1 ms332 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; bool cmp(vector<ii> g1,vector<ii> g2) { return g1.size()>g2.size(); } vector<ii> merge(vector<ii> g1,vector<ii> g2) { while(g2.size()>0) { g1.push_back(g2.back()); g2.pop_back(); } sort(g1.begin(),g1.end()); return g1; } std::vector<int> createFunTour(int N, int Q) { // Find centroid int R,minVal=1e9; for(int i=0;i<N;i++) { int subtree=attractionsBehind(0,i); if(subtree<N/2) continue; if(minVal>subtree) { minVal=subtree; R=i; } } // Find distance and adjacents from centroid R vector<int> adj, dist(N); for(int i=0;i<N;i++) { dist[i]=hoursRequired(R,i); if(dist[i]==1) adj.push_back(i); } // Divide into parts vector<ii> g[adj.size()]; for(int i=0;i<N;i++) { if(i==R) continue; bool valid=false; for(int j=0;j<adj.size();j++) if(adj[j]==i) { g[j].push_back({1,i}); valid=true; break; } if(valid) continue; for(int j=0;j<adj.size()-1;j++) if(dist[i]==hoursRequired(i,adj[j])+1) { g[j].push_back({dist[i],i}); valid=true; break; } if(!valid) g[adj.size()-1].push_back({dist[i],i}); } // Sort sets sort(g,g+adj.size(),cmp); for(int i=0;i<adj.size();i++) sort(g[i].begin(),g[i].end()); vector<int> rs; int turn=0; if(adj.size()==3) { int pre=-1; while(true) { if(g[0].size()+g[1].size()==g[2].size()) { g[0]=merge(g[0],g[1]); g[1]=g[2]; turn=(pre==0||pre==1?turn=1:0); break; } else if(g[0].size()+g[2].size()==g[1].size()) { g[0]=merge(g[0],g[2]); turn=(pre==0||pre==1?turn=1:0); break; } else if(g[1].size()+g[2].size()==g[0].size()) { g[1]=merge(g[1],g[2]); turn=(pre==0?turn=1:0); break; } for(int i=0;i<adj.size();i++) { if(i==pre) continue; if(pre==-1||g[pre].back()<g[i].back()) pre=i; } rs.push_back(g[pre].back().second); g[pre].pop_back(); } } while(g[0].size()>0||g[1].size()>0) { if(g[turn].size()==0) turn^=1; rs.push_back(g[turn].back().second); g[turn].pop_back(); turn^=1; } rs.push_back(R); //for(int u:rs) // cerr<<u<<' '; return rs; }

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int j=0;j<adj.size();j++)
      |               ~^~~~~~~~~~~
fun.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j=0;j<adj.size()-1;j++)
      |               ~^~~~~~~~~~~~~
fun.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<adj.size();i++)
      |              ~^~~~~~~~~~~
fun.cpp:75:9: warning: operation on 'turn' may be undefined [-Wsequence-point]
   75 |     turn=(pre==0||pre==1?turn=1:0);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:79:9: warning: operation on 'turn' may be undefined [-Wsequence-point]
   79 |     turn=(pre==0||pre==1?turn=1:0);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:83:9: warning: operation on 'turn' may be undefined [-Wsequence-point]
   83 |     turn=(pre==0?turn=1:0);
      |     ~~~~^~~~~~~~~~~~~~~~~~
fun.cpp:86:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    for(int i=0;i<adj.size();i++) {
      |                ~^~~~~~~~~~~
#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...