# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960590 | 2024-04-10T16:30:43 Z | TAhmed33 | Longest Trip (IOI23_longesttrip) | C++17 | 126 ms | 2040 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; vector <int> tree[256]; bool vis[256]; vector <int> x; int p[256]; set <int> unvis; void dfs (int pos) { vis[pos] = 1; x.push_back(pos); unvis.erase(pos); while (true) { vector <int> t; for (auto i : unvis) t.push_back(i); int l = 0, r = (int)t.size() - 1, ans = -1; while (l <= r) { int mid = (l + r) / 2; vector <int> g; for (int i = 0; i <= mid; i++) g.push_back(t[i]); if (are_connected({pos}, g)) { r = mid - 1; ans = mid; } else { l = mid + 1; } } if (ans == -1) break; tree[pos].push_back(t[ans]); p[t[ans]] = pos; dfs(t[ans]); } } int get (int x) { if (tree[x].empty()) return x; return get(tree[x][0]); } vector <int> longest_trip (int n, int d) { unvis.clear(); for (int i = 0; i < n; i++) unvis.insert(i); for (int i = 0; i < n; i++) tree[i].clear(); memset(p, -1, sizeof(p)); memset(vis, 0, sizeof(vis)); x.clear(); dfs(0); if (!unvis.empty()) { vector <int> ret = x; for (int i = 0; i < n; i++) { if (!vis[i]) { x.clear(); dfs(i); if ((int)x.size() > (int)ret.size()) ret = x; } } return ret; } int pos = -1; for (int i = 0; i < n; i++) { if ((int)tree[i].size() == 2) { pos = i; } } if (pos == -1) return x; int u = get(tree[pos][0]), v = get(tree[pos][1]); if (p[pos] != -1 && !are_connected({p[pos]}, {u})) { swap(u, v); swap(tree[pos][0], tree[pos][1]); } u = tree[pos][0], v = tree[pos][1]; while (!x.empty() && x.back() != p[pos]) x.pop_back(); vector <int> l; while (true) { l.push_back(u); if (tree[u].empty()) break; u = tree[u][0]; } reverse(l.begin(), l.end()); for (auto i : l) x.push_back(i); x.push_back(pos); while (true) { x.push_back(v); if (tree[v].empty()) break; v = tree[v][0]; } return x; }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 11 ms | 1364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 10 ms | 344 KB | Output is correct |
3 | Correct | 24 ms | 344 KB | Output is correct |
4 | Correct | 34 ms | 764 KB | Output is correct |
5 | Correct | 47 ms | 1268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 504 KB | Output is correct |
2 | Correct | 13 ms | 344 KB | Output is correct |
3 | Correct | 26 ms | 1112 KB | Output is correct |
4 | Correct | 34 ms | 980 KB | Output is correct |
5 | Correct | 48 ms | 892 KB | Output is correct |
6 | Correct | 7 ms | 596 KB | Output is correct |
7 | Correct | 11 ms | 344 KB | Output is correct |
8 | Correct | 23 ms | 600 KB | Output is correct |
9 | Correct | 30 ms | 732 KB | Output is correct |
10 | Correct | 45 ms | 968 KB | Output is correct |
11 | Correct | 48 ms | 1424 KB | Output is correct |
12 | Correct | 48 ms | 1660 KB | Output is correct |
13 | Correct | 44 ms | 1232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 352 KB | Output is correct |
2 | Correct | 11 ms | 344 KB | Output is correct |
3 | Correct | 24 ms | 856 KB | Output is correct |
4 | Correct | 35 ms | 752 KB | Output is correct |
5 | Correct | 42 ms | 1408 KB | Output is correct |
6 | Correct | 7 ms | 344 KB | Output is correct |
7 | Correct | 12 ms | 344 KB | Output is correct |
8 | Correct | 24 ms | 460 KB | Output is correct |
9 | Correct | 28 ms | 856 KB | Output is correct |
10 | Correct | 42 ms | 1096 KB | Output is correct |
11 | Correct | 46 ms | 1228 KB | Output is correct |
12 | Correct | 44 ms | 1368 KB | Output is correct |
13 | Correct | 45 ms | 1788 KB | Output is correct |
14 | Correct | 9 ms | 344 KB | Output is correct |
15 | Correct | 12 ms | 344 KB | Output is correct |
16 | Correct | 15 ms | 344 KB | Output is correct |
17 | Correct | 19 ms | 344 KB | Output is correct |
18 | Correct | 23 ms | 344 KB | Output is correct |
19 | Correct | 31 ms | 856 KB | Output is correct |
20 | Correct | 29 ms | 600 KB | Output is correct |
21 | Correct | 45 ms | 1372 KB | Output is correct |
22 | Correct | 44 ms | 1612 KB | Output is correct |
23 | Correct | 42 ms | 1268 KB | Output is correct |
24 | Correct | 47 ms | 1280 KB | Output is correct |
25 | Correct | 9 ms | 344 KB | Output is correct |
26 | Correct | 11 ms | 344 KB | Output is correct |
27 | Correct | 16 ms | 344 KB | Output is correct |
28 | Correct | 18 ms | 344 KB | Output is correct |
29 | Correct | 14 ms | 596 KB | Output is correct |
30 | Correct | 27 ms | 704 KB | Output is correct |
31 | Correct | 46 ms | 704 KB | Output is correct |
32 | Correct | 51 ms | 960 KB | Output is correct |
33 | Correct | 35 ms | 476 KB | Output is correct |
34 | Correct | 39 ms | 732 KB | Output is correct |
35 | Correct | 48 ms | 872 KB | Output is correct |
36 | Correct | 49 ms | 1040 KB | Output is correct |
37 | Correct | 72 ms | 908 KB | Output is correct |
38 | Correct | 99 ms | 1768 KB | Output is correct |
39 | Correct | 113 ms | 1116 KB | Output is correct |
40 | Correct | 112 ms | 1084 KB | Output is correct |
41 | Correct | 121 ms | 1520 KB | Output is correct |
42 | Correct | 125 ms | 1624 KB | Output is correct |
43 | Correct | 116 ms | 1120 KB | Output is correct |
44 | Correct | 126 ms | 1316 KB | Output is correct |
45 | Correct | 13 ms | 344 KB | Output is correct |
46 | Correct | 11 ms | 344 KB | Output is correct |
47 | Correct | 12 ms | 344 KB | Output is correct |
48 | Correct | 17 ms | 344 KB | Output is correct |
49 | Correct | 15 ms | 344 KB | Output is correct |
50 | Correct | 30 ms | 704 KB | Output is correct |
51 | Correct | 34 ms | 704 KB | Output is correct |
52 | Correct | 42 ms | 972 KB | Output is correct |
53 | Correct | 36 ms | 600 KB | Output is correct |
54 | Correct | 36 ms | 600 KB | Output is correct |
55 | Correct | 41 ms | 724 KB | Output is correct |
56 | Correct | 45 ms | 1372 KB | Output is correct |
57 | Correct | 61 ms | 1116 KB | Output is correct |
58 | Correct | 75 ms | 1332 KB | Output is correct |
59 | Correct | 78 ms | 1028 KB | Output is correct |
60 | Correct | 76 ms | 1156 KB | Output is correct |
61 | Correct | 112 ms | 1376 KB | Output is correct |
62 | Correct | 86 ms | 1264 KB | Output is correct |
63 | Correct | 85 ms | 1404 KB | Output is correct |
64 | Correct | 82 ms | 1060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 10 ms | 344 KB | Output is correct |
3 | Correct | 23 ms | 600 KB | Output is correct |
4 | Partially correct | 31 ms | 1244 KB | Output is partially correct |
5 | Partially correct | 42 ms | 1544 KB | Output is partially correct |
6 | Correct | 9 ms | 344 KB | Output is correct |
7 | Correct | 11 ms | 344 KB | Output is correct |
8 | Correct | 20 ms | 600 KB | Output is correct |
9 | Partially correct | 28 ms | 600 KB | Output is partially correct |
10 | Partially correct | 45 ms | 1012 KB | Output is partially correct |
11 | Partially correct | 48 ms | 856 KB | Output is partially correct |
12 | Partially correct | 39 ms | 1808 KB | Output is partially correct |
13 | Partially correct | 47 ms | 1436 KB | Output is partially correct |
14 | Correct | 8 ms | 344 KB | Output is correct |
15 | Correct | 14 ms | 344 KB | Output is correct |
16 | Correct | 16 ms | 344 KB | Output is correct |
17 | Correct | 19 ms | 596 KB | Output is correct |
18 | Correct | 20 ms | 852 KB | Output is correct |
19 | Partially correct | 29 ms | 600 KB | Output is partially correct |
20 | Partially correct | 27 ms | 856 KB | Output is partially correct |
21 | Correct | 11 ms | 344 KB | Output is correct |
22 | Correct | 10 ms | 344 KB | Output is correct |
23 | Correct | 17 ms | 344 KB | Output is correct |
24 | Correct | 18 ms | 344 KB | Output is correct |
25 | Correct | 16 ms | 344 KB | Output is correct |
26 | Correct | 33 ms | 960 KB | Output is correct |
27 | Partially correct | 46 ms | 696 KB | Output is partially correct |
28 | Partially correct | 47 ms | 956 KB | Output is partially correct |
29 | Partially correct | 32 ms | 856 KB | Output is partially correct |
30 | Partially correct | 40 ms | 600 KB | Output is partially correct |
31 | Partially correct | 45 ms | 600 KB | Output is partially correct |
32 | Correct | 10 ms | 344 KB | Output is correct |
33 | Correct | 9 ms | 344 KB | Output is correct |
34 | Correct | 14 ms | 344 KB | Output is correct |
35 | Correct | 15 ms | 344 KB | Output is correct |
36 | Correct | 18 ms | 344 KB | Output is correct |
37 | Correct | 25 ms | 444 KB | Output is correct |
38 | Partially correct | 35 ms | 716 KB | Output is partially correct |
39 | Partially correct | 40 ms | 956 KB | Output is partially correct |
40 | Partially correct | 28 ms | 600 KB | Output is partially correct |
41 | Partially correct | 31 ms | 480 KB | Output is partially correct |
42 | Partially correct | 37 ms | 728 KB | Output is partially correct |
43 | Partially correct | 47 ms | 1540 KB | Output is partially correct |
44 | Partially correct | 46 ms | 816 KB | Output is partially correct |
45 | Partially correct | 44 ms | 1296 KB | Output is partially correct |
46 | Partially correct | 45 ms | 1808 KB | Output is partially correct |
47 | Partially correct | 51 ms | 1556 KB | Output is partially correct |
48 | Partially correct | 64 ms | 1264 KB | Output is partially correct |
49 | Partially correct | 99 ms | 1124 KB | Output is partially correct |
50 | Partially correct | 110 ms | 1088 KB | Output is partially correct |
51 | Partially correct | 117 ms | 1228 KB | Output is partially correct |
52 | Partially correct | 126 ms | 1104 KB | Output is partially correct |
53 | Partially correct | 113 ms | 1544 KB | Output is partially correct |
54 | Partially correct | 121 ms | 1248 KB | Output is partially correct |
55 | Partially correct | 111 ms | 1372 KB | Output is partially correct |
56 | Partially correct | 72 ms | 1024 KB | Output is partially correct |
57 | Partially correct | 73 ms | 1084 KB | Output is partially correct |
58 | Partially correct | 111 ms | 1600 KB | Output is partially correct |
59 | Partially correct | 112 ms | 1340 KB | Output is partially correct |
60 | Partially correct | 110 ms | 888 KB | Output is partially correct |
61 | Partially correct | 120 ms | 1032 KB | Output is partially correct |
62 | Partially correct | 45 ms | 1268 KB | Output is partially correct |
63 | Partially correct | 66 ms | 924 KB | Output is partially correct |
64 | Partially correct | 67 ms | 1336 KB | Output is partially correct |
65 | Partially correct | 66 ms | 1292 KB | Output is partially correct |
66 | Partially correct | 69 ms | 1592 KB | Output is partially correct |
67 | Partially correct | 108 ms | 1628 KB | Output is partially correct |
68 | Partially correct | 82 ms | 1364 KB | Output is partially correct |
69 | Partially correct | 95 ms | 1512 KB | Output is partially correct |
70 | Partially correct | 83 ms | 1512 KB | Output is partially correct |
71 | Partially correct | 55 ms | 1596 KB | Output is partially correct |
72 | Partially correct | 66 ms | 1612 KB | Output is partially correct |
73 | Partially correct | 92 ms | 1240 KB | Output is partially correct |
74 | Partially correct | 86 ms | 1144 KB | Output is partially correct |
75 | Partially correct | 100 ms | 1528 KB | Output is partially correct |
76 | Partially correct | 84 ms | 1276 KB | Output is partially correct |
77 | Partially correct | 62 ms | 1588 KB | Output is partially correct |
78 | Partially correct | 75 ms | 1440 KB | Output is partially correct |
79 | Partially correct | 89 ms | 1040 KB | Output is partially correct |
80 | Partially correct | 91 ms | 2040 KB | Output is partially correct |
81 | Partially correct | 89 ms | 1244 KB | Output is partially correct |
82 | Partially correct | 98 ms | 1236 KB | Output is partially correct |