# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060284 | 2024-08-15T12:38:53 Z | aykhn | Longest Trip (IOI23_longesttrip) | C++17 | 58 ms | 1840 KB |
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; map<pair<vector<int>, vector<int>>, int> mp; int ask(vector<int> a, vector<int> b) { if (a.empty() || b.empty()) return 0; if (mp.find({a, b}) != mp.end()) return mp[{a, b}]; return mp[{a, b}] = mp[{b, a}] = are_connected(a, b); } vector<int> longest_trip(int n, int D) { mp.clear(); vector<int> v1, v2; v1.push_back(0); for (int i = 1; i < n; i++) { if (ask(v1, {i}) && ask(v2, {i})) { int id1 = -1, id2 = -1; int lx = 0, rx = (int)v1.size() - 1; while (lx < rx) { int m = (lx + rx) >> 1; vector<int> q; for (int i = lx; i <= m; i++) q.push_back(v1[i]); if (ask(q, {i})) rx = m; else lx = m + 1; } id1 = lx; lx = 0, rx = (int)v2.size() - 1; while (lx < rx) { int m = (lx + rx) >> 1; vector<int> q; for (int i = lx; i <= m; i++) q.push_back(v2[i]); if (ask(q, {i})) rx = m; else lx = m + 1; } id2 = lx; vector<int> nw; for (int j = (id2 + 1) % v2.size(); 1; j = (j + 1) % v2.size()) { nw.push_back(v2[j]); if (j == id2) break; } nw.push_back(i), nw.push_back(v1[id1]); for (int j = (id1 + 1) % v1.size(); j != id1; j = (j + 1) % v1.size()) { nw.push_back(v1[j]); } v2.clear(); v1 = nw; } else if (ask(v1, {i})) { vector<int> nw; if (ask({v1.back()}, {i})) { nw = v1; nw.push_back(i); } else { int l = 0, r = (int)v1.size() - 1; while (l < r) { int mid = (l + r) >> 1; vector<int> x; for (int j = 0; j <= mid; j++) { x.push_back(v1[j]); } if (ask(x, {i})) r = mid; else l = mid + 1; } int idx = l; nw.push_back(i), nw.push_back(v1[idx]); for (int j = (idx + 1) % v1.size(); j != idx; j = (j + 1) % v1.size()) { nw.push_back(v1[j]); } } v1 = nw; } else if (ask(v2, {i})) { vector<int> nw; if (ask({v2.back()}, {i})) { nw = v2; nw.push_back(i); } else { int l = 0, r = (int)v2.size() - 1; while (l < r) { int mid = (l + r) >> 1; vector<int> x; for (int j = 0; j <= mid; j++) { x.push_back(v2[j]); } if (ask(x, {i})) r = mid; else l = mid + 1; } int idx = l; nw.push_back(i), nw.push_back(v2[idx]); for (int j = (idx + 1) % v2.size(); j != idx; j = (j + 1) % v2.size()) { nw.push_back(v2[j]); } } v2 = nw; } else v2.push_back(i); } if (v1.size() > v2.size()) return v1; else return v2; };
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 8 ms | 1112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 344 KB | Output is correct |
2 | Correct | 13 ms | 344 KB | Output is correct |
3 | Correct | 19 ms | 476 KB | Output is correct |
4 | Correct | 25 ms | 600 KB | Output is correct |
5 | Correct | 30 ms | 1220 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 340 KB | Output is correct |
2 | Correct | 16 ms | 344 KB | Output is correct |
3 | Correct | 19 ms | 600 KB | Output is correct |
4 | Correct | 23 ms | 624 KB | Output is correct |
5 | Correct | 23 ms | 1360 KB | Output is correct |
6 | Correct | 11 ms | 344 KB | Output is correct |
7 | Correct | 14 ms | 344 KB | Output is correct |
8 | Correct | 12 ms | 344 KB | Output is correct |
9 | Correct | 16 ms | 564 KB | Output is correct |
10 | Correct | 29 ms | 856 KB | Output is correct |
11 | Correct | 22 ms | 760 KB | Output is correct |
12 | Correct | 32 ms | 772 KB | Output is correct |
13 | Correct | 35 ms | 1840 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 | 13 ms | 344 KB | Output is correct |
4 | Correct | 26 ms | 856 KB | Output is correct |
5 | Correct | 31 ms | 1196 KB | Output is correct |
6 | Correct | 12 ms | 344 KB | Output is correct |
7 | Correct | 16 ms | 344 KB | Output is correct |
8 | Correct | 20 ms | 600 KB | Output is correct |
9 | Correct | 17 ms | 572 KB | Output is correct |
10 | Correct | 26 ms | 1196 KB | Output is correct |
11 | Correct | 32 ms | 928 KB | Output is correct |
12 | Correct | 37 ms | 1104 KB | Output is correct |
13 | Correct | 34 ms | 1108 KB | Output is correct |
14 | Correct | 7 ms | 344 KB | Output is correct |
15 | Correct | 13 ms | 344 KB | Output is correct |
16 | Correct | 25 ms | 700 KB | Output is correct |
17 | Correct | 30 ms | 344 KB | Output is correct |
18 | Correct | 19 ms | 340 KB | Output is correct |
19 | Correct | 28 ms | 880 KB | Output is correct |
20 | Correct | 31 ms | 884 KB | Output is correct |
21 | Correct | 41 ms | 1112 KB | Output is correct |
22 | Correct | 44 ms | 1104 KB | Output is correct |
23 | Correct | 39 ms | 856 KB | Output is correct |
24 | Correct | 32 ms | 1136 KB | Output is correct |
25 | Correct | 12 ms | 344 KB | Output is correct |
26 | Correct | 11 ms | 344 KB | Output is correct |
27 | Correct | 13 ms | 344 KB | Output is correct |
28 | Correct | 13 ms | 344 KB | Output is correct |
29 | Correct | 17 ms | 344 KB | Output is correct |
30 | Correct | 25 ms | 344 KB | Output is correct |
31 | Correct | 26 ms | 596 KB | Output is correct |
32 | Correct | 24 ms | 600 KB | Output is correct |
33 | Correct | 28 ms | 344 KB | Output is correct |
34 | Correct | 19 ms | 344 KB | Output is correct |
35 | Correct | 31 ms | 856 KB | Output is correct |
36 | Correct | 31 ms | 796 KB | Output is correct |
37 | Correct | 49 ms | 984 KB | Output is correct |
38 | Correct | 34 ms | 1092 KB | Output is correct |
39 | Correct | 44 ms | 1100 KB | Output is correct |
40 | Correct | 29 ms | 856 KB | Output is correct |
41 | Correct | 37 ms | 1112 KB | Output is correct |
42 | Correct | 37 ms | 1212 KB | Output is correct |
43 | Correct | 29 ms | 1224 KB | Output is correct |
44 | Correct | 34 ms | 972 KB | Output is correct |
45 | Correct | 11 ms | 344 KB | Output is correct |
46 | Correct | 10 ms | 344 KB | Output is correct |
47 | Correct | 16 ms | 344 KB | Output is correct |
48 | Correct | 21 ms | 344 KB | Output is correct |
49 | Correct | 14 ms | 344 KB | Output is correct |
50 | Correct | 24 ms | 344 KB | Output is correct |
51 | Correct | 32 ms | 592 KB | Output is correct |
52 | Correct | 34 ms | 344 KB | Output is correct |
53 | Correct | 22 ms | 856 KB | Output is correct |
54 | Correct | 22 ms | 600 KB | Output is correct |
55 | Correct | 26 ms | 600 KB | Output is correct |
56 | Correct | 22 ms | 856 KB | Output is correct |
57 | Correct | 29 ms | 1160 KB | Output is correct |
58 | Correct | 58 ms | 1560 KB | Output is correct |
59 | Correct | 48 ms | 1296 KB | Output is correct |
60 | Correct | 34 ms | 1308 KB | Output is correct |
61 | Correct | 40 ms | 1112 KB | Output is correct |
62 | Correct | 40 ms | 1324 KB | Output is correct |
63 | Correct | 37 ms | 1308 KB | Output is correct |
64 | Correct | 42 ms | 1104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 344 KB | Output is correct |
2 | Correct | 15 ms | 344 KB | Output is correct |
3 | Correct | 19 ms | 344 KB | Output is correct |
4 | Correct | 24 ms | 600 KB | Output is correct |
5 | Partially correct | 38 ms | 952 KB | Output is partially correct |
6 | Correct | 10 ms | 344 KB | Output is correct |
7 | Correct | 11 ms | 344 KB | Output is correct |
8 | Correct | 20 ms | 344 KB | Output is correct |
9 | Correct | 20 ms | 592 KB | Output is correct |
10 | Partially correct | 36 ms | 856 KB | Output is partially correct |
11 | Partially correct | 31 ms | 920 KB | Output is partially correct |
12 | Partially correct | 22 ms | 856 KB | Output is partially correct |
13 | Partially correct | 26 ms | 1112 KB | Output is partially correct |
14 | Correct | 13 ms | 344 KB | Output is correct |
15 | Correct | 17 ms | 344 KB | Output is correct |
16 | Correct | 24 ms | 600 KB | Output is correct |
17 | Correct | 21 ms | 344 KB | Output is correct |
18 | Correct | 23 ms | 500 KB | Output is correct |
19 | Correct | 31 ms | 592 KB | Output is correct |
20 | Correct | 33 ms | 600 KB | Output is correct |
21 | Correct | 11 ms | 344 KB | Output is correct |
22 | Correct | 9 ms | 344 KB | Output is correct |
23 | Correct | 12 ms | 344 KB | Output is correct |
24 | Correct | 18 ms | 344 KB | Output is correct |
25 | Correct | 21 ms | 344 KB | Output is correct |
26 | Correct | 25 ms | 340 KB | Output is correct |
27 | Correct | 22 ms | 848 KB | Output is correct |
28 | Correct | 30 ms | 344 KB | Output is correct |
29 | Correct | 25 ms | 344 KB | Output is correct |
30 | Correct | 23 ms | 344 KB | Output is correct |
31 | Correct | 19 ms | 344 KB | Output is correct |
32 | Correct | 10 ms | 344 KB | Output is correct |
33 | Correct | 14 ms | 344 KB | Output is correct |
34 | Correct | 14 ms | 344 KB | Output is correct |
35 | Correct | 17 ms | 344 KB | Output is correct |
36 | Correct | 13 ms | 344 KB | Output is correct |
37 | Partially correct | 18 ms | 508 KB | Output is partially correct |
38 | Correct | 26 ms | 856 KB | Output is correct |
39 | Correct | 24 ms | 556 KB | Output is correct |
40 | Partially correct | 18 ms | 600 KB | Output is partially correct |
41 | Correct | 17 ms | 344 KB | Output is correct |
42 | Partially correct | 37 ms | 596 KB | Output is partially correct |
43 | Partially correct | 38 ms | 1028 KB | Output is partially correct |
44 | Partially correct | 28 ms | 1268 KB | Output is partially correct |
45 | Partially correct | 28 ms | 1112 KB | Output is partially correct |
46 | Partially correct | 34 ms | 1244 KB | Output is partially correct |
47 | Partially correct | 29 ms | 1104 KB | Output is partially correct |
48 | Partially correct | 27 ms | 856 KB | Output is partially correct |
49 | Partially correct | 29 ms | 984 KB | Output is partially correct |
50 | Partially correct | 32 ms | 1360 KB | Output is partially correct |
51 | Partially correct | 33 ms | 1104 KB | Output is partially correct |
52 | Partially correct | 32 ms | 1104 KB | Output is partially correct |
53 | Partially correct | 29 ms | 1104 KB | Output is partially correct |
54 | Partially correct | 41 ms | 856 KB | Output is partially correct |
55 | Partially correct | 38 ms | 1368 KB | Output is partially correct |
56 | Partially correct | 36 ms | 1112 KB | Output is partially correct |
57 | Partially correct | 30 ms | 1000 KB | Output is partially correct |
58 | Partially correct | 33 ms | 1112 KB | Output is partially correct |
59 | Partially correct | 35 ms | 956 KB | Output is partially correct |
60 | Partially correct | 38 ms | 936 KB | Output is partially correct |
61 | Partially correct | 32 ms | 964 KB | Output is partially correct |
62 | Partially correct | 27 ms | 1112 KB | Output is partially correct |
63 | Partially correct | 29 ms | 1028 KB | Output is partially correct |
64 | Partially correct | 53 ms | 1368 KB | Output is partially correct |
65 | Partially correct | 35 ms | 1316 KB | Output is partially correct |
66 | Partially correct | 34 ms | 1104 KB | Output is partially correct |
67 | Partially correct | 42 ms | 1112 KB | Output is partially correct |
68 | Partially correct | 47 ms | 1208 KB | Output is partially correct |
69 | Partially correct | 37 ms | 1104 KB | Output is partially correct |
70 | Partially correct | 39 ms | 1360 KB | Output is partially correct |
71 | Partially correct | 29 ms | 1256 KB | Output is partially correct |
72 | Partially correct | 33 ms | 1084 KB | Output is partially correct |
73 | Partially correct | 39 ms | 1360 KB | Output is partially correct |
74 | Partially correct | 31 ms | 1112 KB | Output is partially correct |
75 | Partially correct | 39 ms | 1044 KB | Output is partially correct |
76 | Partially correct | 40 ms | 1368 KB | Output is partially correct |
77 | Partially correct | 36 ms | 1112 KB | Output is partially correct |
78 | Partially correct | 32 ms | 1104 KB | Output is partially correct |
79 | Partially correct | 32 ms | 1244 KB | Output is partially correct |
80 | Partially correct | 33 ms | 1048 KB | Output is partially correct |
81 | Partially correct | 38 ms | 960 KB | Output is partially correct |
82 | Partially correct | 48 ms | 1400 KB | Output is partially correct |