Submission #841599

#TimeUsernameProblemLanguageResultExecution timeMemory
841599andrei_c1Longest Trip (IOI23_longesttrip)C++17
30 / 100
9 ms608 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; uint64_t randomAddress() { char *p = new char; delete p; return uint64_t(p); } uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (randomAddress() | 1); // mt19937 rng(SEED); void concat(vector<int> &t1, vector<int> &t2) { if(t1.size() < t2.size()) { swap(t1, t2); } while(!t2.empty()) { t1.emplace_back(t2.back()); t2.pop_back(); } } std::vector<int> longest_trip(int n, int D) { srand(SEED); vector<int> res, ord(n); iota(ord.begin(), ord.end(), 0); random_shuffle(ord.begin(), ord.end()); if(D == 3) { for(const auto &u: ord) { res.emplace_back(u); } } else if(D == 2) { deque<int> dq; dq.emplace_back(ord.back()); ord.pop_back(); for(const auto &u: ord) { if(are_connected({u}, {dq.back()})) { dq.emplace_back(u); } else { assert(are_connected({u}, {dq.front()})); dq.emplace_front(u); } } for(const auto &u: dq) { res.emplace_back(u); } } else { vector<int> t1, t2; t1.emplace_back(ord.back()); ord.pop_back(); t2.emplace_back(ord.back()); ord.pop_back(); for(const auto &u: ord) { if(are_connected({u}, {t1.back()})) { t1.emplace_back(u); } else if(are_connected({u}, {t2.back()})) { t2.emplace_back(u); } else { concat(t1, t2); t2.emplace_back(u); } } if(t1.size() < t2.size()) { swap(t1, t2); } for(const auto &u: t1) { res.emplace_back(u); } } return res; }
#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...