제출 #699479

#제출 시각아이디문제언어결과실행 시간메모리
699479cig32즐거운 행로 (APIO20_fun)C++17
0 / 100
1 ms340 KiB
#include "bits/stdc++.h" #include "fun.h" using namespace std; #include <vector> std::vector<int> createFunTour(int N, int Q) { if(N == 2) return {0, 1}; int rt=-1; int ma=-1; for(int i=0; i<N; i++) { int ab = attractionsBehind(0, i); if(N - ab <= N/2) { if(N - ab > ma) { ma=N - ab, rt=i; } } } assert(rt>=0); int dist[N]; for(int i=0; i<N; i++) dist[i] = hoursRequired(rt, i); vector<int> leader; int M = 0; for(int i=0; i<N; i++) { if(dist[i] == 1) { M++; leader.push_back(i); } } priority_queue<pair<int, int> > depths[M]; for(int i=0; i<N; i++) { int grp = M-1; for(int j=0; j<M-1; j++) { int hr = hoursRequired(leader[j], i); if(hr + 1 == dist[i]) { grp = j; break; } } depths[grp].push({dist[i], i}); } vector<int> ans; ma = -1; int id; for(int i=0; i<M; i++) { if((int) (depths[i].size()) > ma) { ma = depths[i].size(); id = i; } } ans.push_back(depths[id].top().second); depths[id].pop(); for(int i=0; i<N-1; i++) { ma = -1; int id2; for(int j=0; j<M; j++) { if((int) (depths[j].size()) > ma) { ma = depths[j].size(); id2 = j; } } if(id == id2) { ma = -1; for(int j=0; j<M; j++) { if(j != id && depths[j].size() && depths[j].top().first > ma) { ma = depths[j].top().first; id2 = j; } } } ans.push_back(depths[id2].top().second); depths[id2].pop(); id = id2; } return ans; }

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:61:5: warning: 'id2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |     if(id == id2) {
      |     ^~
fun.cpp:43:7: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |   int id;
      |       ^~
#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...