제출 #567012

#제출 시각아이디문제언어결과실행 시간메모리
567012hibiki즐거운 행로 (APIO20_fun)C++11
0 / 100
1 ms308 KiB
#include "fun.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second int n,q,mid; int dist[100005]; vector<int> head,sz,ans; vector<pair<int,int> > nh[3]; int fi_mid() { int base = 0, po, near, midbase = n / 2; if(n % 2) midbase++; near = abs(midbase - attractionsBehind(1, 0)); po = 0; for(int i = 1; i < n; i++) { int ret = attractionsBehind(base, i); if(abs(midbase - ret) < near) { near = abs(midbase - ret); po = i; } } return po; } void fi_dist() { for(int i = 0; i < n; i++) { if(i == mid) dist[i] = 0; else dist[i] = hoursRequired(i, mid); if(dist[i] == 1) { head.pb(i); sz.pb(n - attractionsBehind(i, mid)); } } } void fi_nh() { int ti = 0; for(int i = 0; i < n; i++) { if(i == mid) continue; if(dist[i] == 1) { nh[ti++].pb({dist[i], i}); continue; } int ask0 = attractionsBehind(i, head[0]); int ask1 = attractionsBehind(i, head[1]); if(ask0 != sz[0]) nh[0].pb({dist[i],i}); else if(ask1 != sz[1]) nh[1].pb({dist[i],i}); else nh[2].pb({dist[i],i}); } } vector<int> createFunTour(int N, int Q) { n = N, q = Q; mid = fi_mid(); // printf("p1\n"); fi_dist(); // printf("p2\n"); fi_nh(); // printf("p3\n"); // printf("%d %d\n",mid,head.size()); // for(int i = 0; i < nh[2].size(); i++) // printf("%d ",nh[2][i].s); // printf("\n"); int idx_last[3] = {-1,-1,-1}; int cur,last,best = 0; for(int i = 0; i < head.size(); i++) { sort(nh[i].begin(),nh[i].end()); idx_last[i] = nh[i].size() - 1; if(nh[i][idx_last[i]].f > best) { cur = i; last = nh[i][idx_last[i]].s; best = nh[i][idx_last[i]].f; } } ans.pb(last); idx_last[cur]--; // printf("%d\n",last); for(int i = 1; i < n - 1; i++) { best = 0; int prev_cur = cur; for(int j = 0; j < head.size(); j++) { if(j == prev_cur || idx_last[j] == -1) continue; if(nh[j][idx_last[j]].f > best) { cur = j; last = nh[j][idx_last[j]].s; best = nh[j][idx_last[j]].f; } } ans.pb(last); // printf("%d\n",last); idx_last[cur]--; } ans.pb(mid); // printf("%d\n",mid); return ans; }

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i = 0; i < head.size(); i++)
      |                    ~~^~~~~~~~~~~~~
fun.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int j = 0; j < head.size(); j++)
      |                        ~~^~~~~~~~~~~~~
fun.cpp:95:17: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |     idx_last[cur]--;
      |     ~~~~~~~~~~~~^
#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...