# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1072441 | 2024-08-23T19:06:25 Z | HorizonWest | Longest Trip (IOI23_longesttrip) | C++17 | 930 ms | 1752 KB |
#include <iostream> #include <complex> #include <iomanip> #include <vector> #include <algorithm> #include <functional> #include <bitset> #include <queue> #include <map> #include <stack> #include <cmath> #include <cstdint> #include <cassert> #include "longesttrip.h" using namespace std; vector <int> longest_trip(int n, int d) { vector <vector<int>> v(n, vector <int> ()), s(n, vector <int> (n, -1)); auto add = [&] (int a, int b) -> void { if(s[a][b] == -1){ s[a][b] = s[b][a] = 1; v[a].push_back(b); v[b].push_back(a); } }; if(d == 3){ for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++) { add(i, j); } } }else if(d == 2){ for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { if(s[i][j] == -1){ s[i][j] = are_connected({ i }, { j }); if(s[i][j] == 0){ for(int k = 0; k < n; k++){ add(i, k); add(j, k); } }else{ s[i][j] = -1; add(i, j); } } } } } else if(d == 1){ for(int i = 0; i < n; i++) { for(int j = i+1; j < n; j++) { if(s[i][j] == -1){ s[i][j] = are_connected({ i }, { j }); if(s[i][j] == 1) { s[i][j] = -1; add(i, j); } } } } } vector <int> pass(n), ans, path; auto dfs = [&] (auto dfs, int node, int parent) -> void { path.push_back(node); pass[node] = 1; if(path.size() > ans.size()) ans = path; for(auto& u : v[node]) if(!pass[u]){ if(v[u].size() != n) dfs(dfs, u, node); } for(auto& u : v[node]) if(!pass[u]) { dfs(dfs, u, node); } path.pop_back(); }; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ pass[j] = 0; } if(ans.size() == n) break; dfs(dfs, i, i); } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 188 ms | 1004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 2 ms | 600 KB | Output is correct |
5 | Correct | 3 ms | 1068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 344 KB | Output is correct |
2 | Correct | 27 ms | 344 KB | Output is correct |
3 | Correct | 156 ms | 504 KB | Output is correct |
4 | Correct | 355 ms | 600 KB | Output is correct |
5 | Correct | 724 ms | 1060 KB | Output is correct |
6 | Incorrect | 1 ms | 344 KB | Incorrect |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 344 KB | Output is correct |
2 | Correct | 30 ms | 340 KB | Output is correct |
3 | Correct | 138 ms | 464 KB | Output is correct |
4 | Correct | 369 ms | 744 KB | Output is correct |
5 | Correct | 750 ms | 1308 KB | Output is correct |
6 | Correct | 10 ms | 344 KB | Output is correct |
7 | Correct | 26 ms | 344 KB | Output is correct |
8 | Correct | 150 ms | 452 KB | Output is correct |
9 | Correct | 247 ms | 780 KB | Output is correct |
10 | Correct | 781 ms | 1148 KB | Output is correct |
11 | Correct | 820 ms | 1080 KB | Output is correct |
12 | Correct | 812 ms | 1404 KB | Output is correct |
13 | Correct | 836 ms | 1480 KB | Output is correct |
14 | Correct | 10 ms | 344 KB | Output is correct |
15 | Correct | 12 ms | 344 KB | Output is correct |
16 | Correct | 45 ms | 344 KB | Output is correct |
17 | Correct | 95 ms | 344 KB | Output is correct |
18 | Correct | 151 ms | 456 KB | Output is correct |
19 | Correct | 307 ms | 788 KB | Output is correct |
20 | Correct | 333 ms | 560 KB | Output is correct |
21 | Correct | 834 ms | 1376 KB | Output is correct |
22 | Correct | 899 ms | 1308 KB | Output is correct |
23 | Correct | 864 ms | 1752 KB | Output is correct |
24 | Correct | 824 ms | 1156 KB | Output is correct |
25 | Correct | 7 ms | 344 KB | Output is correct |
26 | Correct | 9 ms | 344 KB | Output is correct |
27 | Correct | 25 ms | 416 KB | Output is correct |
28 | Correct | 29 ms | 408 KB | Output is correct |
29 | Correct | 20 ms | 408 KB | Output is correct |
30 | Correct | 191 ms | 604 KB | Output is correct |
31 | Correct | 204 ms | 456 KB | Output is correct |
32 | Correct | 181 ms | 452 KB | Output is correct |
33 | Correct | 358 ms | 588 KB | Output is correct |
34 | Correct | 330 ms | 748 KB | Output is correct |
35 | Correct | 325 ms | 596 KB | Output is correct |
36 | Correct | 930 ms | 1264 KB | Output is correct |
37 | Correct | 920 ms | 1272 KB | Output is correct |
38 | Correct | 830 ms | 1288 KB | Output is correct |
39 | Correct | 762 ms | 1316 KB | Output is correct |
40 | Correct | 796 ms | 1048 KB | Output is correct |
41 | Correct | 790 ms | 868 KB | Output is correct |
42 | Correct | 745 ms | 1040 KB | Output is correct |
43 | Correct | 705 ms | 1356 KB | Output is correct |
44 | Correct | 796 ms | 1060 KB | Output is correct |
45 | Correct | 9 ms | 344 KB | Output is correct |
46 | Correct | 13 ms | 344 KB | Output is correct |
47 | Correct | 29 ms | 344 KB | Output is correct |
48 | Correct | 23 ms | 596 KB | Output is correct |
49 | Correct | 21 ms | 340 KB | Output is correct |
50 | Correct | 174 ms | 452 KB | Output is correct |
51 | Correct | 184 ms | 464 KB | Output is correct |
52 | Correct | 198 ms | 456 KB | Output is correct |
53 | Correct | 273 ms | 600 KB | Output is correct |
54 | Correct | 318 ms | 552 KB | Output is correct |
55 | Correct | 298 ms | 600 KB | Output is correct |
56 | Correct | 916 ms | 1060 KB | Output is correct |
57 | Correct | 848 ms | 1120 KB | Output is correct |
58 | Correct | 806 ms | 1068 KB | Output is correct |
59 | Correct | 857 ms | 1012 KB | Output is correct |
60 | Correct | 875 ms | 1296 KB | Output is correct |
61 | Correct | 892 ms | 1128 KB | Output is correct |
62 | Correct | 882 ms | 940 KB | Output is correct |
63 | Correct | 888 ms | 1224 KB | Output is correct |
64 | Correct | 895 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 33 ms | 344 KB | Output is correct |
3 | Partially correct | 138 ms | 724 KB | Output is partially correct |
4 | Partially correct | 399 ms | 1132 KB | Output is partially correct |
5 | Partially correct | 829 ms | 1236 KB | Output is partially correct |
6 | Correct | 7 ms | 344 KB | Output is correct |
7 | Correct | 24 ms | 344 KB | Output is correct |
8 | Partially correct | 133 ms | 456 KB | Output is partially correct |
9 | Partially correct | 295 ms | 1112 KB | Output is partially correct |
10 | Partially correct | 874 ms | 1320 KB | Output is partially correct |
11 | Partially correct | 834 ms | 1332 KB | Output is partially correct |
12 | Partially correct | 809 ms | 1364 KB | Output is partially correct |
13 | Partially correct | 845 ms | 1388 KB | Output is partially correct |
14 | Correct | 8 ms | 344 KB | Output is correct |
15 | Correct | 11 ms | 344 KB | Output is correct |
16 | Incorrect | 8 ms | 344 KB | Incorrect |
17 | Halted | 0 ms | 0 KB | - |