# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
840523 | 2023-08-31T13:22:02 Z | arbuzick | 가장 긴 여행 (IOI23_longesttrip) | C++17 | 890 ms | 548 KB |
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; vector<int> longest_trip(int n, int d) { if (d == 3) { vector<int> ans(n); iota(ans.begin(), ans.end(), 0); return ans; } if (d == 2) { vector<int> ans = {0}; vector<int> used(n); used[0] = 1; while (ans.size() < n) { int nxt = -1; for (int i = 0; i < n; ++i) { if (!used[i] && are_connected({ans.back()}, {i})) { nxt = i; used[i] = 1; break; } } if (nxt == -1) { reverse(ans.begin(), ans.end()); for (int i = 0; i < n; ++i) { if (!used[i] && are_connected({ans.back()}, {i})) { nxt = i; used[i] = 1; break; } } } ans.push_back(nxt); } return ans; } if (d == 1) { vector<vector<int>> g(n, vector<int>(n)); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (are_connected({i}, {j})) { g[i][j] = g[j][i] = 1; } } } vector<int> ans = {0}; vector<int> used(n); used[0] = 1; auto try_to_add = [&]() { int nxt = -1; for (int i = 0; i < n; ++i) { if (!used[i] && g[ans.back()][i]) { nxt = i; used[i] = 1; break; } } if (nxt == -1) { return false; } ans.push_back(nxt); return true; }; while (true) { if (!try_to_add()) { break; } } if (ans.size() < n) { reverse(ans.begin(), ans.end()); if (try_to_add()) { while (true) { if (!try_to_add()) { break; } } } else { for (int _ = 0; _ < (int)ans.size(); ++_) { reverse(ans.begin(), ans.end()); int vl = ans.back(); ans.pop_back(); reverse(ans.begin(), ans.end()); ans.push_back(vl); if (try_to_add()) { while (true) { if (!try_to_add()) { break; } } break; } } } } if (ans.size() * 2 < n) { ans.clear(); for (int i = 0; i < n; ++i) { if (!used[i]) { ans.push_back(i); } } } return ans; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 208 KB | Output is correct |
2 | Correct | 210 ms | 464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 208 KB | Output is correct |
2 | Correct | 1 ms | 208 KB | Output is correct |
3 | Correct | 1 ms | 208 KB | Output is correct |
4 | Correct | 0 ms | 208 KB | Output is correct |
5 | Correct | 0 ms | 208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 208 KB | Output is correct |
2 | Correct | 9 ms | 208 KB | Output is correct |
3 | Correct | 10 ms | 208 KB | Output is correct |
4 | Correct | 6 ms | 208 KB | Output is correct |
5 | Correct | 6 ms | 208 KB | Output is correct |
6 | Correct | 11 ms | 208 KB | Output is correct |
7 | Correct | 7 ms | 208 KB | Output is correct |
8 | Correct | 8 ms | 208 KB | Output is correct |
9 | Correct | 7 ms | 208 KB | Output is correct |
10 | Correct | 10 ms | 208 KB | Output is correct |
11 | Correct | 10 ms | 208 KB | Output is correct |
12 | Correct | 7 ms | 296 KB | Output is correct |
13 | Correct | 8 ms | 208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 208 KB | Output is correct |
2 | Correct | 37 ms | 208 KB | Output is correct |
3 | Correct | 132 ms | 208 KB | Output is correct |
4 | Correct | 416 ms | 348 KB | Output is correct |
5 | Correct | 755 ms | 464 KB | Output is correct |
6 | Correct | 16 ms | 208 KB | Output is correct |
7 | Correct | 18 ms | 208 KB | Output is correct |
8 | Correct | 150 ms | 208 KB | Output is correct |
9 | Correct | 308 ms | 336 KB | Output is correct |
10 | Correct | 871 ms | 464 KB | Output is correct |
11 | Correct | 760 ms | 464 KB | Output is correct |
12 | Correct | 858 ms | 464 KB | Output is correct |
13 | Correct | 833 ms | 464 KB | Output is correct |
14 | Correct | 9 ms | 208 KB | Output is correct |
15 | Correct | 18 ms | 208 KB | Output is correct |
16 | Correct | 53 ms | 208 KB | Output is correct |
17 | Correct | 96 ms | 208 KB | Output is correct |
18 | Correct | 166 ms | 208 KB | Output is correct |
19 | Correct | 349 ms | 336 KB | Output is correct |
20 | Correct | 309 ms | 336 KB | Output is correct |
21 | Correct | 783 ms | 464 KB | Output is correct |
22 | Correct | 729 ms | 464 KB | Output is correct |
23 | Correct | 755 ms | 464 KB | Output is correct |
24 | Correct | 777 ms | 464 KB | Output is correct |
25 | Correct | 13 ms | 208 KB | Output is correct |
26 | Correct | 12 ms | 208 KB | Output is correct |
27 | Correct | 32 ms | 208 KB | Output is correct |
28 | Correct | 32 ms | 208 KB | Output is correct |
29 | Correct | 28 ms | 208 KB | Output is correct |
30 | Correct | 146 ms | 208 KB | Output is correct |
31 | Correct | 165 ms | 208 KB | Output is correct |
32 | Correct | 212 ms | 208 KB | Output is correct |
33 | Correct | 289 ms | 336 KB | Output is correct |
34 | Correct | 310 ms | 336 KB | Output is correct |
35 | Correct | 308 ms | 336 KB | Output is correct |
36 | Correct | 705 ms | 464 KB | Output is correct |
37 | Correct | 742 ms | 464 KB | Output is correct |
38 | Correct | 797 ms | 464 KB | Output is correct |
39 | Correct | 861 ms | 464 KB | Output is correct |
40 | Correct | 812 ms | 464 KB | Output is correct |
41 | Correct | 859 ms | 464 KB | Output is correct |
42 | Correct | 796 ms | 464 KB | Output is correct |
43 | Correct | 793 ms | 464 KB | Output is correct |
44 | Correct | 788 ms | 464 KB | Output is correct |
45 | Correct | 11 ms | 208 KB | Output is correct |
46 | Correct | 12 ms | 208 KB | Output is correct |
47 | Correct | 26 ms | 208 KB | Output is correct |
48 | Correct | 31 ms | 208 KB | Output is correct |
49 | Correct | 30 ms | 208 KB | Output is correct |
50 | Correct | 211 ms | 208 KB | Output is correct |
51 | Correct | 197 ms | 208 KB | Output is correct |
52 | Correct | 207 ms | 208 KB | Output is correct |
53 | Correct | 329 ms | 336 KB | Output is correct |
54 | Correct | 348 ms | 336 KB | Output is correct |
55 | Correct | 279 ms | 336 KB | Output is correct |
56 | Correct | 853 ms | 464 KB | Output is correct |
57 | Correct | 718 ms | 464 KB | Output is correct |
58 | Correct | 852 ms | 464 KB | Output is correct |
59 | Correct | 835 ms | 544 KB | Output is correct |
60 | Correct | 799 ms | 464 KB | Output is correct |
61 | Correct | 796 ms | 464 KB | Output is correct |
62 | Correct | 839 ms | 464 KB | Output is correct |
63 | Correct | 890 ms | 464 KB | Output is correct |
64 | Correct | 799 ms | 464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 208 KB | Output is correct |
2 | Correct | 30 ms | 208 KB | Output is correct |
3 | Partially correct | 164 ms | 208 KB | Output is partially correct |
4 | Partially correct | 453 ms | 348 KB | Output is partially correct |
5 | Partially correct | 861 ms | 464 KB | Output is partially correct |
6 | Correct | 10 ms | 208 KB | Output is correct |
7 | Correct | 33 ms | 208 KB | Output is correct |
8 | Partially correct | 167 ms | 208 KB | Output is partially correct |
9 | Partially correct | 337 ms | 336 KB | Output is partially correct |
10 | Partially correct | 827 ms | 548 KB | Output is partially correct |
11 | Partially correct | 682 ms | 464 KB | Output is partially correct |
12 | Partially correct | 774 ms | 464 KB | Output is partially correct |
13 | Partially correct | 731 ms | 464 KB | Output is partially correct |
14 | Correct | 6 ms | 208 KB | Output is correct |
15 | Correct | 13 ms | 208 KB | Output is correct |
16 | Correct | 50 ms | 208 KB | Output is correct |
17 | Partially correct | 112 ms | 208 KB | Output is partially correct |
18 | Partially correct | 137 ms | 208 KB | Output is partially correct |
19 | Partially correct | 297 ms | 336 KB | Output is partially correct |
20 | Partially correct | 279 ms | 336 KB | Output is partially correct |
21 | Correct | 12 ms | 208 KB | Output is correct |
22 | Correct | 7 ms | 208 KB | Output is correct |
23 | Correct | 38 ms | 208 KB | Output is correct |
24 | Correct | 35 ms | 208 KB | Output is correct |
25 | Correct | 35 ms | 208 KB | Output is correct |
26 | Partially correct | 234 ms | 208 KB | Output is partially correct |
27 | Partially correct | 198 ms | 208 KB | Output is partially correct |
28 | Partially correct | 181 ms | 208 KB | Output is partially correct |
29 | Partially correct | 280 ms | 336 KB | Output is partially correct |
30 | Partially correct | 290 ms | 336 KB | Output is partially correct |
31 | Partially correct | 281 ms | 336 KB | Output is partially correct |
32 | Correct | 11 ms | 208 KB | Output is correct |
33 | Correct | 11 ms | 208 KB | Output is correct |
34 | Correct | 31 ms | 208 KB | Output is correct |
35 | Correct | 23 ms | 208 KB | Output is correct |
36 | Correct | 36 ms | 208 KB | Output is correct |
37 | Partially correct | 228 ms | 208 KB | Output is partially correct |
38 | Partially correct | 171 ms | 208 KB | Output is partially correct |
39 | Partially correct | 219 ms | 208 KB | Output is partially correct |
40 | Partially correct | 319 ms | 336 KB | Output is partially correct |
41 | Partially correct | 265 ms | 336 KB | Output is partially correct |
42 | Partially correct | 351 ms | 336 KB | Output is partially correct |
43 | Partially correct | 801 ms | 464 KB | Output is partially correct |
44 | Partially correct | 846 ms | 464 KB | Output is partially correct |
45 | Partially correct | 695 ms | 464 KB | Output is partially correct |
46 | Partially correct | 701 ms | 464 KB | Output is partially correct |
47 | Partially correct | 747 ms | 464 KB | Output is partially correct |
48 | Partially correct | 843 ms | 464 KB | Output is partially correct |
49 | Partially correct | 840 ms | 464 KB | Output is partially correct |
50 | Partially correct | 756 ms | 464 KB | Output is partially correct |
51 | Partially correct | 746 ms | 464 KB | Output is partially correct |
52 | Partially correct | 774 ms | 464 KB | Output is partially correct |
53 | Partially correct | 809 ms | 464 KB | Output is partially correct |
54 | Partially correct | 775 ms | 464 KB | Output is partially correct |
55 | Partially correct | 876 ms | 464 KB | Output is partially correct |
56 | Partially correct | 813 ms | 464 KB | Output is partially correct |
57 | Partially correct | 757 ms | 464 KB | Output is partially correct |
58 | Partially correct | 803 ms | 464 KB | Output is partially correct |
59 | Partially correct | 725 ms | 464 KB | Output is partially correct |
60 | Partially correct | 808 ms | 464 KB | Output is partially correct |
61 | Partially correct | 756 ms | 464 KB | Output is partially correct |
62 | Partially correct | 652 ms | 464 KB | Output is partially correct |
63 | Partially correct | 737 ms | 464 KB | Output is partially correct |
64 | Partially correct | 792 ms | 464 KB | Output is partially correct |
65 | Partially correct | 810 ms | 464 KB | Output is partially correct |
66 | Partially correct | 714 ms | 464 KB | Output is partially correct |
67 | Partially correct | 837 ms | 464 KB | Output is partially correct |
68 | Partially correct | 691 ms | 464 KB | Output is partially correct |
69 | Partially correct | 791 ms | 464 KB | Output is partially correct |
70 | Partially correct | 812 ms | 464 KB | Output is partially correct |
71 | Partially correct | 765 ms | 464 KB | Output is partially correct |
72 | Partially correct | 755 ms | 464 KB | Output is partially correct |
73 | Partially correct | 777 ms | 464 KB | Output is partially correct |
74 | Partially correct | 787 ms | 464 KB | Output is partially correct |
75 | Partially correct | 797 ms | 464 KB | Output is partially correct |
76 | Partially correct | 824 ms | 464 KB | Output is partially correct |
77 | Partially correct | 800 ms | 464 KB | Output is partially correct |
78 | Partially correct | 801 ms | 464 KB | Output is partially correct |
79 | Partially correct | 756 ms | 464 KB | Output is partially correct |
80 | Partially correct | 694 ms | 464 KB | Output is partially correct |
81 | Partially correct | 722 ms | 464 KB | Output is partially correct |
82 | Partially correct | 699 ms | 464 KB | Output is partially correct |