제출 #851476

#제출 시각아이디문제언어결과실행 시간메모리
851476batmendbar가장 긴 여행 (IOI23_longesttrip)C++17
0 / 100
0 ms344 KiB
#include "longesttrip.h" #include <algorithm> #include <random> #include <stack> using namespace std; vector<int> longest_trip(int N, int D) { stack<int> big, small; vector<int> nodes; for (int i = 0; i < N; i++) nodes.push_back(i); random_device rd; mt19937 g(rd()); shuffle(nodes.begin(), nodes.end(), g); big.push(nodes[0]); small.push(nodes[1]); bool guarantee = false; for (int i = 2; i < N; i++) { if (are_connected(vector<int>{big.top()}, vector<int>{i})) { big.push(i); guarantee = false; } else if (guarantee) { small.push(i); } else if (are_connected(vector<int>{small.top()}, vector<int>{i})) { small.push(i); guarantee = true; } else { if (small.size() == 1) guarantee = true; while (!small.empty()) { big.push(small.top()); small.pop(); } small.push(i); } } vector<int> ans; stack<int> s = (big.size() < small.size()) ? small : big; while(!s.empty()) { ans.push_back(s.top()); s.pop(); } 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...