# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
846710 | 2023-09-08T09:30:45 Z | Trisanu_Das | Longest Trip (IOI23_longesttrip) | C++17 | 282 ms | 344 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; vector<int> longest_trip(int N, int D) { vector<int> ans = {0}; bool vis[N]; vis[0] = true; bool adj[N][N]; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(i != j) adj[i][j] = adj[j][i] = are_connected({i}, {j}); while (true) { if (ans.size() == N) return ans; bool flag = false; for (int i = 0; i < N && !flag; i++) { if (!vis[i]) { if (adj[ans[0]][i]) { ans.insert(ans.begin(), i); flag = true; vis[i] = true; break; } if (adj[ans.back()][i]) { ans.push_back(i); flag = true; vis[i] = true; break; } for (int j = 0; j < ans.size(); j++) { if (adj[ans[j]][i]) { vector<int> new_path; new_path.insert(new_path.end(), ans.begin() + j + 1, ans.end()); new_path.insert(new_path.end(), ans.begin(), ans.begin() + j + 1); ans = new_path; ans.push_back(i); flag = true; vis[i] = true; break; } } } } if (!flag) { if (ans.size() >= (N - ans.size())) return ans; ans.clear(); for (int i = 0; i < N; ++i) if (!vis[i]) ans.push_back(i); return ans; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Incorrect | 175 ms | 344 KB | too many calls |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 344 KB | Incorrect |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 344 KB | Incorrect |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 344 KB | Output is correct |
2 | Correct | 53 ms | 344 KB | Output is correct |
3 | Correct | 282 ms | 344 KB | Output is correct |
4 | Incorrect | 168 ms | 344 KB | Incorrect |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 344 KB | Output is correct |
2 | Incorrect | 1 ms | 344 KB | Incorrect |
3 | Halted | 0 ms | 0 KB | - |