Submission #1187744

#TimeUsernameProblemLanguageResultExecution timeMemory
1187744MatteoArcari가장 긴 여행 (IOI23_longesttrip)C++20
0 / 100
3 ms416 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; bool are_connected(vector<int> A, vector<int> B); vector<int> connect(vector<int> a, vector<int> b) { reverse(a.begin(), a.end()); for (auto x: b) a.push_back(x); return a; } vector<int> longest_trip(int n, int d) { vector<vector<int>> paths = {{0}, {1}, {2}}; for (int i = 3; i < n; i++) { for (int k: {0, 1, 2}) { if (are_connected({paths[k].back()}, {i})) { paths[k].push_back(i); break; } } } vector<int> pathA, pathB; if (are_connected({0}, {1})) { pathA = connect(paths[0], paths[1]); pathB = paths[2]; } else if (are_connected({0}, {2})) { pathA = connect(paths[0], paths[2]); pathB = paths[1]; } else { pathA = connect(paths[2], paths[1]); pathB = paths[0]; } assert(max(pathA.size(), pathB.size()) >= (n + 1) / 2); if (pathA.size() > pathB.size()) return pathA; return pathB; }
#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...