제출 #717177

#제출 시각아이디문제언어결과실행 시간메모리
717177LittleCube즐거운 행로 (APIO20_fun)C++14
31 / 100
119 ms17244 KiB
#include "fun.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> #define pii pair<int, int> #define F first #define S second using namespace std; vector<int> createFunTour(int N, int Q) { priority_queue<pii> pq; for (int i = 1; i < N; i++) pq.push(pii(attractionsBehind(0, i), i)); // N - 1 int c = 0; while (!pq.empty() && pq.top().F > N / 2) { auto [sz, u] = pq.top(); pq.pop(); if (hoursRequired(c, u) == 1) // <= (N - 1) / 2 c = u; } vector<int> d(N), order(N), sol, tree[3]; vector<int> tmp[2]; for (int i = 0; i < N; i++) d[i] = hoursRequired(c, i), order[i] = i; sort(order.begin(), order.end(), [&](int i, int j) { return d[i] < d[j]; }); auto diffSubtree = [&](int i, int j) { if (i == c || j == c) return true; return hoursRequired(i, j) == d[i] + d[j]; }; for (int i = 0; i < N; i++) if (i != c) { if (tree[0].empty() || !diffSubtree(tree[0].front(), i)) tree[0].emplace_back(i); else if (tree[1].empty() || !diffSubtree(tree[1].front(), i)) tree[1].emplace_back(i); else tree[2].emplace_back(i); } if (tree[2].size() > tree[1].size()) tree[1].emplace_back(c); else tree[2].emplace_back(c); for (int i = 0; i < 3; i++) sort(tree[i].begin(), tree[i].end(), [&](int i, int j) { return d[i] > d[j]; }); vector<int> color(N); for (int i = 0; i < 3; i++) for (int j : tree[i]) color[j] = i; auto solve = [&](vector<int> A, vector<int> B, vector<int> C) { vector<int> res(N); int L = (N + 1) / 2, R = N / 2; reverse(B.begin(), B.end()); while (A.size() < L) { A.emplace_back(C.back()); C.pop_back(); } while (B.size() < R) { B.emplace_back(C.back()); C.pop_back(); } reverse(B.begin(), B.end()); stable_sort(A.begin(), A.end(), [&](int i, int j) { return d[i] > d[j]; }); stable_sort(B.begin(), B.end(), [&](int i, int j) { return d[i] > d[j]; }); for (int i = 0; i < L; i++) res[i * 2] = A[i]; for (int i = 0; i < R; i++) res[i * 2 + 1] = B[i]; for (int i = 0; i + 1 < N; i++) if (color[res[i]] == color[res[i + 1]]) return vector<int>{}; return res; }; sol = solve(tree[0], tree[1], tree[2]); if (sol.size()) return sol; sol = solve(tree[0], tree[2], tree[1]); if (sol.size()) return sol; sol = solve(tree[1], tree[0], tree[2]); if (sol.size()) return sol; sol = solve(tree[1], tree[2], tree[0]); if (sol.size()) return sol; sol = solve(tree[2], tree[1], tree[0]); if (sol.size()) return sol; sol = solve(tree[2], tree[0], tree[1]); if (sol.size()) return sol; sol = vector<int>(2 * N, -1); auto diffSubtree2 = [&](int i, int j) { return color[i] != color[j]; }; int t = 0; for (int i = 0; i < N; i++) { if (tmp[t ^ 1].empty() || diffSubtree2(order[i], tmp[t ^ 1].back())) { tmp[t].emplace_back(order[i]); if (tmp[t].size() + t > tmp[t ^ 1].size()) t ^= 1; } else tmp[t ^ 1].emplace_back(order[i]); } for (int i = 0; i < tmp[0].size(); i++) sol[i * 2] = tmp[0][i]; for (int i = 0; i < tmp[1].size(); i++) sol[i * 2 + 1] = tmp[1][i]; tmp[0].clear(), tmp[1].clear(); int over = -1, cnt = 0, last = 0; for (int i = 2 * N - 1; i > 0; i--) { if (sol[i] == -1 && sol[i - 1] >= 0) { over = sol[i - 1], cnt++; tmp[1].emplace_back(sol[i - 1]); last = i - 2; } } // cerr << c << '\n'; // for (int i = 0; i < 2 * N; i++) // cerr << sol[i] << " \n"[i == 2 * N - 1]; sol.resize(N); for (; cnt >= 0 && last >= 0; last--) { if (diffSubtree2(sol[last], over)) { if(cnt == 0) break; tmp[0].emplace_back(sol[last]); cnt--; } else { tmp[1].emplace_back(sol[last]); last--; tmp[0].emplace_back(sol[last]); } } sort(tmp[0].begin(), tmp[0].end(), [&](int i, int j) { return d[i] > d[j]; }); sort(tmp[1].begin(), tmp[1].end(), [&](int i, int j) { return d[i] > d[j]; }); reverse(sol.begin(), sol.end()); for (int i = 0; i < tmp[0].size(); i++) sol[i * 2] = tmp[0][i]; for (int i = 0; i < tmp[1].size(); i++) sol[i * 2 + 1] = tmp[1][i]; return sol; }

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:19:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |         auto [sz, u] = pq.top();
      |              ^
fun.cpp: In lambda function:
fun.cpp:68:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |         while (A.size() < L)
      |                ~~~~~~~~~^~~
fun.cpp:73:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |         while (B.size() < R)
      |                ~~~~~~~~~^~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:132:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |     for (int i = 0; i < tmp[0].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
fun.cpp:134:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |     for (int i = 0; i < tmp[1].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
fun.cpp:175:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |     for (int i = 0; i < tmp[0].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
fun.cpp:177:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |     for (int i = 0; i < tmp[1].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...