# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
939696 | 2024-03-06T16:42:38 Z | weajink | Longest Trip (IOI23_longesttrip) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> sciezka[2]; void dodaj_wierzcholek(int v){ if (!sciezka[0].size() || are_connected({v},{sciezka[0].back()})){ sciezka[0].push_back(v); return; } if (!sciezka[1].size() || are_connected({v},{sciezka[1].back()})){ sciezka[1].push_back(v); return; } for (int i = (int)sciezka[1].size()-1; i >= 0; i--) sciezka[0].push_back(sciezka[1][i]); sciezka[1] = {v}; } vector<int> longest_trip(int N, int D){ sciezka[0].clear(); sciezka[1].clear(); for (int i = 1; i <= N; i++) dodaj_wierzcholek(i); if (sciezka[0].size() < sciezka[1].size()) swap(sciezka[0],sciezka[1]); return sciezka[0]; }