제출 #1310344

#제출 시각아이디문제언어결과실행 시간메모리
1310344AliMark71가장 긴 여행 (IOI23_longesttrip)C++20
15 / 100
1074 ms412 KiB
#include "longesttrip.h" #include <bits/stdc++.h> template<typename T> using vec = std::vector<T>; using namespace std; std::vector<int> longest_trip(int N, int D) { vec<int> nodes(N); for (int i = 0; i < N; i++) nodes[i] = i; if (D == 3) return nodes; if (D == 2) { deque<int> path{0, are_connected({0}, {1}) ? 1 : 2}; nodes.erase(find(nodes.begin(), nodes.end(), path.front())); nodes.erase(find(nodes.begin(), nodes.end(), path.back())); while (!nodes.empty()) { auto u = nodes.back(); nodes.pop_back(); if (are_connected({path.front()}, {u})) path.push_front(u); else path.push_back(u); } return vec<int>(path.begin(), path.end()); } list<int> path[2] = {{0}, {1}}; nodes.erase(find(nodes.begin(), nodes.end(), path[0].back())); nodes.erase(find(nodes.begin(), nodes.end(), path[1].back())); while (!nodes.empty()) { auto u = nodes.back(); nodes.pop_back(); if (are_connected({path[0].back()}, {u})) path[0].push_back(u); else if (are_connected({path[1].back()}, {u})) path[1].push_back(u); else { path[1].reverse(); path[0].splice(path[0].end(), path[1]); path[1] = {u}; } } return path[0].size() > path[1].size() ? vec<int>(path[0].begin(), path[1].end()) : vec<int>(path[1].begin(), path[1].end()); }
#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...