제출 #395368

#제출 시각아이디문제언어결과실행 시간메모리
395368syl123456즐거운 행로 (APIO20_fun)C++17
47 / 100
143 ms25492 KiB
#include "fun.h" #include <bits/stdc++.h> #define all(i) (i).begin(), (i).end() using namespace std; typedef pair<int, int> pi; std::vector<int> createFunTour(int N, int Q) { if (N == 2) { vector<int> ans(1, 0); ans.push_back(1); return ans; } vector<int> dep(N), sz(N); dep[0] = 0, sz[0] = N; int cen = 0; for (int i = 1; i < N; ++i) { dep[i] = hoursRequired(0, i); sz[i] = attractionsBehind(0, i); if (dep[i] > dep[cen] && sz[i] > N / 2) cen = i; } vector<int> v[3], ch; if (cen != 0) { vector<int> dep0(all(dep)); for (int i = 0; i < N; ++i) dep[i] = i == cen ? 0 : hoursRequired(cen, i); for (int i = 0; i < N; ++i) if (dep[i] == 1) ch.push_back(i); for (int i = 0; i < ch.size(); ++i) if (dep0[ch[i]] < dep0[cen]) swap(ch[i], ch[0]); for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]); for (int i = 0; i < N; ++i) if (dep[i] > 1) { bool b = false; if (dep0[i] != dep0[cen] + dep[i]) v[0].push_back(i), b = true; else for (int j = 1; j < ch.size() - 1; ++j) if (dep[i] == 1 + hoursRequired(ch[j], i)) { v[j].push_back(i); b = true; break; } if (!b) v[ch.size() - 1].push_back(i); } } else { for (int i = 0; i < N; ++i) dep[i] = i == cen ? 0 : hoursRequired(cen, i); for (int i = 0; i < N; ++i) if (dep[i] == 1) ch.push_back(i); for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]); for (int i = 0; i < N; ++i) if (dep[i] > 1) { bool b = false; for (int j = 0; j < ch.size() - 1; ++j) if (dep[i] == 1 + hoursRequired(ch[j], i)) { v[j].push_back(i); b = true; break; } if (!b) v[ch.size() - 1].push_back(i); } } for (int i = 0; i < 3; ++i) sort(all(v[i]), [&](int x, int y) { return dep[x] < dep[y]; }); vector<int> ans; bool vis[N]{}; int pre = -1; for (int i = 0; i < N - 1; ++i) { int tmp = -1; for (int j = 0; j < 3; ++j) if (j != pre && !v[j].empty() && (tmp == -1 || dep[v[j].back()] > dep[v[tmp].back()] || (dep[v[j].back()] == dep[v[tmp].back()] && v[j].size() > v[tmp].size()))) tmp = j; if (ch.size() == 2 && i == 0) tmp = v[0].size() < v[1].size(); assert(tmp != -1); ans.push_back(v[tmp].back()); v[tmp].pop_back(); pre = tmp; } ans.push_back(cen); return ans; } /* * n depth * n sz * cen = max dep && sz > n/2 * rt != cen ? n dis cen + n two ch * : n first ch + n second ch * */

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int i = 0; i < ch.size(); ++i) if (dep0[ch[i]] < dep0[cen]) swap(ch[i], ch[0]);
      |                         ~~^~~~~~~~~~~
fun.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]);
      |                         ~~^~~~~~~~~~~
fun.cpp:30:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             else for (int j = 1; j < ch.size() - 1; ++j)
      |                                  ~~^~~~~~~~~~~~~~~
fun.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]);
      |                         ~~^~~~~~~~~~~
fun.cpp:45:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for (int j = 0; j < ch.size() - 1; ++j)
      |                             ~~^~~~~~~~~~~~~~~
fun.cpp:58:10: warning: unused variable 'vis' [-Wunused-variable]
   58 |     bool vis[N]{};
      |          ^~~
#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...