제출 #1002331

#제출 시각아이디문제언어결과실행 시간메모리
1002331Wael가장 긴 여행 (IOI23_longesttrip)C++17
70 / 100
16 ms856 KiB
#include "longesttrip.h" //#include "grader.cpp" #include <bits/stdc++.h> using namespace std; using i64 = long long; vector<int> add(vector<int> a, vector<int> b) { for (auto j : b) { a.push_back(j); } return a; } vector<int> longest_trip(int N, int D) { int n = N; vector<int> a, b, c; auto ask = [&](int x, int y) -> bool { return are_connected(vector<int>{x}, vector<int>{y}); }; for (int i = 1; i < n; ++i) { b.push_back(i); } a.push_back(0); while (true) { vector<int> last{a.back()}; if (c.size() && are_connected(last, c)) { int l = 1, r = c.size(); while (l <= r) { int mid = (l + r) / 2; if (are_connected(last, vector<int>(c.begin(), c.begin() + mid))) { r = mid - 1; } else { l = mid + 1; } } ++r; a.emplace_back(c[r - 1]); a = add(a, vector<int>(c.begin(), c.begin() + r - 1)); a = add(a, vector<int>(c.begin() + r, c.end())); c.clear(); continue; } while (b.size() && are_connected(last, vector<int>{b.back()}) == 0) { c.push_back(b.back()); b.pop_back(); } if (b.size()) { a.push_back(b.back()); b.pop_back(); } else { if (c.size() && are_connected(a, c) == 0) { if (a.size() < c.size()) { swap(a, c); } } else { if (c.size()) { int l = 1, r = c.size(); while (l <= r) { int mid = (l + r) / 2; if (are_connected(a, vector<int>(c.begin(), c.begin() + mid))) { r = mid - 1; } else { l = mid + 1; } } ++r; int x = c[r - 1]; while (ask(a[0], x) == 0 && ask(a.back(), x) == 0) { a.push_back(a[0]); a.erase(a.begin()); } if (ask(a[0], x)) { reverse(a.begin(), a.end()); } a.emplace_back(x); a = add(a, vector<int>(c.begin(), c.begin() + r - 1)); a = add(a, vector<int>(c.begin() + r, c.end())); c.clear(); } } break; } } return a; }
#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...