Submission #1060259

#TimeUsernameProblemLanguageResultExecution timeMemory
1060259qilbyLongest Trip (IOI23_longesttrip)C++17
100 / 100
13 ms644 KiB
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; vector < int > longest_trip(int n, int d) { bool g = 0; vector < int > a = {0}, b = {1}; for (int i = 2; i < n; i++) { if (g) { if (are_connected({a.back()}, {i})) a.push_back(i), g = 0; else b.push_back(i); } else { if (are_connected({a.back()}, {i})) a.push_back(i); else if (are_connected({b.back()}, {i})) b.push_back(i), g = 1; else { reverse(b.begin(), b.end()); for (auto v : b) a.push_back(v); b = {i}; } } } if (are_connected(a, b)) { if (are_connected({a.back()}, {b.back()})) { reverse(b.begin(), b.end()); for (auto v : b) a.push_back(v); return a; } else if (are_connected({a.back()}, {b[0]})) { for (auto v : b) a.push_back(v); return a; } else if (are_connected({a[0]}, {b.back()})) { for (auto v : a) b.push_back(v); return b; } else if (are_connected({a[0]}, {b[0]})) { reverse(b.begin(), b.end()); for (auto v : a) b.push_back(v); return b; } else { int l = 0, r = (int)a.size() - 1; while (l < r) { int mid = (l + r) >> 1; vector < int > crr; for (int i = 0; i <= mid; i++) crr.push_back(a[i]); if (are_connected(crr, b)) r = mid; else l = mid + 1; } int p = l; l = 0, r = (int)b.size() - 1; while (l < r) { int mid = (l + r) >> 1; vector < int > crr; for (int i = 0; i <= mid; i++) crr.push_back(b[i]); if (are_connected({a[p]}, crr)) r = mid; else l = mid + 1; } vector < int > res; for (int i = (p + 1) % (int)a.size(), s = 0; s < (int)a.size(); s++, i = (i + 1) % (int)a.size()) res.push_back(a[i]); for (int i = l, s = 0; s < (int)b.size(); s++, i = (i + 1) % (int)b.size()) res.push_back(b[i]); return res; } } else { return ((int)a.size() > (int)b.size() ? a : b); } return {}; }
#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...