Submission #840783

#TimeUsernameProblemLanguageResultExecution timeMemory
840783emeraldblockLongest Trip (IOI23_longesttrip)C++17
100 / 100
22 ms336 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; std::vector<int> longest_trip(int N, int D) { vector<int> s1({0}),s2({1}); auto mrg = [&]() { while (!s2.empty()) { s1.push_back(s2.back()); s2.pop_back(); } }; bool sep = false; for (int i = 2; i < N; ++i) { if (are_connected({s1.back()}, {i})) { s1.push_back(i); sep = false; } else if (sep || are_connected({s2.back()}, {i})) { s2.push_back(i); sep = true; } else { mrg(); s2.push_back(i); } } if (!are_connected(s1, s2)) { return s1.size() >= s2.size() ? s1 : s2; } auto rot = [&](vector<int>& a, const vector<int>& b) { if (are_connected(b,{a.front()})) { reverse(a.begin(),a.end()); return; } int lo = 0, hi = a.size(); while (hi-lo>1) { int mid = (lo+hi)/2; vector<int> v; for (int i = mid; i < hi; ++i) { v.push_back(a[i]); } if (!are_connected(b, v)) { hi = mid; } else { lo = mid; } } rotate(a.begin(),a.begin()+hi,a.end()); }; rot(s2,s1); rot(s1,{s2.back()}); mrg(); return s1; }
#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...