Submission #1064102

#TimeUsernameProblemLanguageResultExecution timeMemory
1064102DorostWefLongest Trip (IOI23_longesttrip)C++17
15 / 100
12 ms432 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; #define ask are_connected std::vector<int> longest_trip(int N, int D) { int n = N; vector <int> A = {0}, B; for (int i = 1; i < n; i++) { if (B.empty()) { bool f = ask ({A.back()}, {i}); if (f) A.push_back(i); else { B.push_back(i); } } else { if (ask ({A.back()}, {B[0]})) { for (int x : B) A.push_back(x); B.clear(); i--; } else if (ask ({A.back()}, {i})) { A.push_back(i); } else { B.push_back(i); } } }/* cout << "A : "; for (int x : A) cout << x << ' '; cout << '\n'; cout << "B : "; for (int y : B) cout << y << ' '; cout << '\n';*/ if (B.empty()) return A; if (!ask (A, B)) { if (A.size() >= B.size()) return A; return B; } if (ask ({A[0]}, {B[0]})) { reverse (A.begin(), A.end()); for (int x : B) { A.push_back(x); } return A; } else { bool f; if (A.size() >= 2) { f = ask ({A[0]}, {A.back()}); if (!f) { for (int x : B) { A.push_back(x); } return A; } } if (B.size() >= 2) { f = ask ({B[0]}, {B.back()}); if (!f) { for (int x : A) { B.push_back(x); } return B; } } } int l = -1, r = (int)A.size() - 1; while (r - l > 1) { int mid = (l + r) >> 1; vector <int> C; for (int i = 0; i <= mid; i++) { C.push_back(A[i]); } if (ask (C, B)) { r = mid; } else { l = mid; } } vector <int> wef = {A[r]}; int ww1 = r; l = -1, r = (int)B.size() - 1; while (r - l > 1) { int mid = (l + r) >> 1; vector <int> C; for (int i = 0; i <= mid; i++) { C.push_back(B[i]); } if (ask (C, wef)) { r = mid; } else { l = mid; } } int ww2 = r; vector <int> ans; for (int i = ww1 - 1; i >= 0; i--) { ans.push_back(A[i]); } for (int i = (int)A.size() - 1; i >= ww1; i--) { ans.push_back(A[i]); } for (int i = ww2; i < (int)B.size(); i++) { ans.push_back(B[i]); } for (int i = 0; i < ww2; i++) { ans.push_back(B[i]); } return ans; }
#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...