# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960598 | 2024-04-10T16:39:21 Z | TAhmed33 | Longest Trip (IOI23_longesttrip) | C++17 | 90 ms | 2156 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; int cnt; 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 (!unvis.empty()) { vector <int> t; for (auto i : unvis) t.push_back(i); if (!are_connected({pos}, t)) break; 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]); cnt++; assert(cnt <= 3000); 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) { cnt = 0; 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 | 1 ms | 344 KB | Output is correct |
2 | Correct | 13 ms | 1636 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 596 KB | Output is correct |
2 | Correct | 16 ms | 344 KB | Output is correct |
3 | Correct | 30 ms | 464 KB | Output is correct |
4 | Correct | 42 ms | 988 KB | Output is correct |
5 | Correct | 52 ms | 1632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 344 KB | Output is correct |
2 | Correct | 18 ms | 344 KB | Output is correct |
3 | Correct | 26 ms | 340 KB | Output is correct |
4 | Correct | 45 ms | 1256 KB | Output is correct |
5 | Correct | 59 ms | 1696 KB | Output is correct |
6 | Correct | 11 ms | 344 KB | Output is correct |
7 | Correct | 14 ms | 344 KB | Output is correct |
8 | Correct | 29 ms | 796 KB | Output is correct |
9 | Correct | 41 ms | 864 KB | Output is correct |
10 | Correct | 55 ms | 1184 KB | Output is correct |
11 | Correct | 61 ms | 2124 KB | Output is correct |
12 | Correct | 61 ms | 1620 KB | Output is correct |
13 | Correct | 56 ms | 1836 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 344 KB | Output is correct |
2 | Correct | 17 ms | 596 KB | Output is correct |
3 | Correct | 25 ms | 344 KB | Output is correct |
4 | Correct | 43 ms | 1228 KB | Output is correct |
5 | Correct | 56 ms | 1580 KB | Output is correct |
6 | Correct | 9 ms | 344 KB | Output is correct |
7 | Correct | 20 ms | 344 KB | Output is correct |
8 | Correct | 26 ms | 344 KB | Output is correct |
9 | Correct | 41 ms | 1232 KB | Output is correct |
10 | Correct | 55 ms | 1916 KB | Output is correct |
11 | Correct | 57 ms | 1176 KB | Output is correct |
12 | Correct | 61 ms | 1296 KB | Output is correct |
13 | Correct | 64 ms | 1276 KB | Output is correct |
14 | Correct | 11 ms | 344 KB | Output is correct |
15 | Correct | 13 ms | 344 KB | Output is correct |
16 | Correct | 20 ms | 344 KB | Output is correct |
17 | Correct | 25 ms | 452 KB | Output is correct |
18 | Correct | 28 ms | 344 KB | Output is correct |
19 | Correct | 36 ms | 876 KB | Output is correct |
20 | Correct | 34 ms | 984 KB | Output is correct |
21 | Correct | 54 ms | 1168 KB | Output is correct |
22 | Correct | 56 ms | 2156 KB | Output is correct |
23 | Correct | 56 ms | 1064 KB | Output is correct |
24 | Correct | 59 ms | 1148 KB | Output is correct |
25 | Correct | 11 ms | 344 KB | Output is correct |
26 | Correct | 12 ms | 344 KB | Output is correct |
27 | Correct | 20 ms | 344 KB | Output is correct |
28 | Correct | 22 ms | 596 KB | Output is correct |
29 | Correct | 21 ms | 344 KB | Output is correct |
30 | Correct | 42 ms | 712 KB | Output is correct |
31 | Correct | 42 ms | 628 KB | Output is correct |
32 | Correct | 36 ms | 464 KB | Output is correct |
33 | Correct | 45 ms | 724 KB | Output is correct |
34 | Correct | 43 ms | 600 KB | Output is correct |
35 | Correct | 50 ms | 976 KB | Output is correct |
36 | Correct | 64 ms | 1244 KB | Output is correct |
37 | Correct | 67 ms | 1608 KB | Output is correct |
38 | Correct | 73 ms | 1664 KB | Output is correct |
39 | Correct | 77 ms | 1884 KB | Output is correct |
40 | Correct | 84 ms | 1628 KB | Output is correct |
41 | Correct | 76 ms | 880 KB | Output is correct |
42 | Correct | 90 ms | 1396 KB | Output is correct |
43 | Correct | 90 ms | 1592 KB | Output is correct |
44 | Correct | 89 ms | 1536 KB | Output is correct |
45 | Correct | 12 ms | 344 KB | Output is correct |
46 | Correct | 16 ms | 344 KB | Output is correct |
47 | Correct | 22 ms | 596 KB | Output is correct |
48 | Correct | 20 ms | 344 KB | Output is correct |
49 | Correct | 27 ms | 344 KB | Output is correct |
50 | Correct | 37 ms | 1216 KB | Output is correct |
51 | Correct | 42 ms | 968 KB | Output is correct |
52 | Correct | 41 ms | 972 KB | Output is correct |
53 | Correct | 43 ms | 720 KB | Output is correct |
54 | Correct | 45 ms | 980 KB | Output is correct |
55 | Correct | 44 ms | 724 KB | Output is correct |
56 | Correct | 57 ms | 1628 KB | Output is correct |
57 | Correct | 65 ms | 1624 KB | Output is correct |
58 | Correct | 70 ms | 1316 KB | Output is correct |
59 | Correct | 70 ms | 1376 KB | Output is correct |
60 | Correct | 78 ms | 2104 KB | Output is correct |
61 | Correct | 76 ms | 1356 KB | Output is correct |
62 | Correct | 78 ms | 1640 KB | Output is correct |
63 | Correct | 75 ms | 1672 KB | Output is correct |
64 | Correct | 83 ms | 1184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 344 KB | Output is correct |
2 | Correct | 14 ms | 344 KB | Output is correct |
3 | Correct | 26 ms | 344 KB | Output is correct |
4 | Partially correct | 40 ms | 1228 KB | Output is partially correct |
5 | Partially correct | 56 ms | 1608 KB | Output is partially correct |
6 | Correct | 9 ms | 344 KB | Output is correct |
7 | Correct | 16 ms | 348 KB | Output is correct |
8 | Correct | 29 ms | 344 KB | Output is correct |
9 | Partially correct | 36 ms | 728 KB | Output is partially correct |
10 | Partially correct | 57 ms | 1628 KB | Output is partially correct |
11 | Partially correct | 60 ms | 1000 KB | Output is partially correct |
12 | Partially correct | 64 ms | 1856 KB | Output is partially correct |
13 | Partially correct | 56 ms | 1616 KB | Output is partially correct |
14 | Correct | 8 ms | 344 KB | Output is correct |
15 | Correct | 12 ms | 344 KB | Output is correct |
16 | Correct | 18 ms | 344 KB | Output is correct |
17 | Correct | 21 ms | 444 KB | Output is correct |
18 | Correct | 26 ms | 764 KB | Output is correct |
19 | Partially correct | 36 ms | 476 KB | Output is partially correct |
20 | Partially correct | 41 ms | 976 KB | Output is partially correct |
21 | Correct | 13 ms | 344 KB | Output is correct |
22 | Correct | 12 ms | 344 KB | Output is correct |
23 | Correct | 24 ms | 344 KB | Output is correct |
24 | Correct | 21 ms | 344 KB | Output is correct |
25 | Correct | 18 ms | 344 KB | Output is correct |
26 | Partially correct | 38 ms | 712 KB | Output is partially correct |
27 | Partially correct | 40 ms | 960 KB | Output is partially correct |
28 | Correct | 38 ms | 712 KB | Output is correct |
29 | Partially correct | 42 ms | 980 KB | Output is partially correct |
30 | Partially correct | 46 ms | 720 KB | Output is partially correct |
31 | Partially correct | 46 ms | 980 KB | Output is partially correct |
32 | Correct | 13 ms | 344 KB | Output is correct |
33 | Correct | 14 ms | 344 KB | Output is correct |
34 | Correct | 21 ms | 344 KB | Output is correct |
35 | Correct | 17 ms | 344 KB | Output is correct |
36 | Correct | 16 ms | 344 KB | Output is correct |
37 | Partially correct | 37 ms | 452 KB | Output is partially correct |
38 | Partially correct | 41 ms | 1216 KB | Output is partially correct |
39 | Correct | 36 ms | 704 KB | Output is correct |
40 | Partially correct | 41 ms | 484 KB | Output is partially correct |
41 | Partially correct | 43 ms | 724 KB | Output is partially correct |
42 | Partially correct | 40 ms | 500 KB | Output is partially correct |
43 | Partially correct | 61 ms | 1088 KB | Output is partially correct |
44 | Partially correct | 61 ms | 1160 KB | Output is partially correct |
45 | Partially correct | 59 ms | 1396 KB | Output is partially correct |
46 | Partially correct | 64 ms | 1356 KB | Output is partially correct |
47 | Partially correct | 55 ms | 1168 KB | Output is partially correct |
48 | Partially correct | 71 ms | 1372 KB | Output is partially correct |
49 | Partially correct | 70 ms | 1180 KB | Output is partially correct |
50 | Partially correct | 75 ms | 884 KB | Output is partially correct |
51 | Partially correct | 81 ms | 1396 KB | Output is partially correct |
52 | Partially correct | 83 ms | 1132 KB | Output is partially correct |
53 | Partially correct | 83 ms | 1644 KB | Output is partially correct |
54 | Partially correct | 78 ms | 1596 KB | Output is partially correct |
55 | Partially correct | 76 ms | 1848 KB | Output is partially correct |
56 | Partially correct | 70 ms | 924 KB | Output is partially correct |
57 | Partially correct | 70 ms | 1880 KB | Output is partially correct |
58 | Partially correct | 75 ms | 1140 KB | Output is partially correct |
59 | Partially correct | 79 ms | 1572 KB | Output is partially correct |
60 | Partially correct | 81 ms | 1644 KB | Output is partially correct |
61 | Partially correct | 85 ms | 1156 KB | Output is partially correct |
62 | Partially correct | 54 ms | 1112 KB | Output is partially correct |
63 | Partially correct | 61 ms | 1676 KB | Output is partially correct |
64 | Partially correct | 70 ms | 1056 KB | Output is partially correct |
65 | Partially correct | 66 ms | 1692 KB | Output is partially correct |
66 | Partially correct | 69 ms | 1356 KB | Output is partially correct |
67 | Partially correct | 80 ms | 1372 KB | Output is partially correct |
68 | Partially correct | 74 ms | 1400 KB | Output is partially correct |
69 | Partially correct | 77 ms | 1152 KB | Output is partially correct |
70 | Partially correct | 68 ms | 1604 KB | Output is partially correct |
71 | Partially correct | 64 ms | 1392 KB | Output is partially correct |
72 | Partially correct | 73 ms | 1648 KB | Output is partially correct |
73 | Partially correct | 82 ms | 1348 KB | Output is partially correct |
74 | Partially correct | 81 ms | 1232 KB | Output is partially correct |
75 | Partially correct | 82 ms | 1832 KB | Output is partially correct |
76 | Partially correct | 79 ms | 1300 KB | Output is partially correct |
77 | Partially correct | 65 ms | 1124 KB | Output is partially correct |
78 | Partially correct | 67 ms | 1600 KB | Output is partially correct |
79 | Partially correct | 76 ms | 1396 KB | Output is partially correct |
80 | Partially correct | 75 ms | 1868 KB | Output is partially correct |
81 | Partially correct | 72 ms | 1120 KB | Output is partially correct |
82 | Partially correct | 81 ms | 1136 KB | Output is partially correct |