# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927899 | 2024-02-15T13:52:54 Z | aykhn | Longest Trip (IOI23_longesttrip) | C++17 | 816 ms | 1368 KB |
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; int A[300][300]; int ask(vector<int> a, vector<int> b) { for (int x : a) { for (int y : b) { if (A[x][y]) return 1; } } return 0; } vector<int> longest_trip(int n, int D) { int c = 0; for (int i = 0; i < n; i++) { A[i][i] = 1; for (int j = i + 1; j < n; j++) { A[i][j] = A[j][i] = are_connected({i}, {j}); } } vector<int> used(n, 0); vector<int> v1, v2; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { if (ask({i}, {j})) { v1.push_back(i), v1.push_back(j); used[i] = used[j] = 1; break; } } if (!v1.empty()) break; } for (int i = 0; i < n; i++) { if (used[i]) continue; used[i] = 1; if (ask(v1, {i}) && ask(v2, {i})) { assert(++c <= 1); int id1 = -1, id2 = -1; for (int j = 0; j < v1.size(); j++) { if (ask({v1[j]}, {i})) { id1 = j; break; } } for (int j = 0; j < v2.size(); j++) { if (ask({v2[j]}, {i})) { id2 = j; break; } } assert(id1 != -1 && id2 != -1); 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; int idx = -1; if (ask({v1[0]}, {i})) { nw.push_back(i); for (int x : v1) nw.push_back(x); } else if (ask({v1.back()}, {i})) { nw = v1; nw.push_back(i); } else { for (int j = 0; j < v1.size(); j++) { if (ask({i}, {v1[j]})) { idx = j; break; } } 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; int idx = -1; if (ask({v2[0]}, {i})) { nw.push_back(i); for (int x : v2) nw.push_back(x); } else if (ask({v2.back()}, {i})) { nw = v2; nw.push_back(i); } else { for (int j = 0; j < v2.size(); j++) { if (ask({i}, {v2[j]})) { idx = j; break; } } 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; };
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 169 ms | 720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 344 KB | Output is correct |
2 | Correct | 20 ms | 344 KB | Output is correct |
3 | Correct | 136 ms | 856 KB | Output is correct |
4 | Correct | 320 ms | 564 KB | Output is correct |
5 | Correct | 648 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 20 ms | 344 KB | Output is correct |
3 | Correct | 112 ms | 340 KB | Output is correct |
4 | Correct | 343 ms | 592 KB | Output is correct |
5 | Correct | 713 ms | 720 KB | Output is correct |
6 | Correct | 7 ms | 344 KB | Output is correct |
7 | Correct | 21 ms | 344 KB | Output is correct |
8 | Correct | 107 ms | 496 KB | Output is correct |
9 | Correct | 244 ms | 548 KB | Output is correct |
10 | Correct | 655 ms | 716 KB | Output is correct |
11 | Correct | 679 ms | 1112 KB | Output is correct |
12 | Correct | 723 ms | 720 KB | Output is correct |
13 | Correct | 709 ms | 856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 23 ms | 344 KB | Output is correct |
3 | Correct | 117 ms | 600 KB | Output is correct |
4 | Correct | 355 ms | 672 KB | Output is correct |
5 | Correct | 748 ms | 716 KB | Output is correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 21 ms | 344 KB | Output is correct |
8 | Correct | 108 ms | 612 KB | Output is correct |
9 | Correct | 271 ms | 548 KB | Output is correct |
10 | Correct | 707 ms | 720 KB | Output is correct |
11 | Correct | 691 ms | 720 KB | Output is correct |
12 | Correct | 674 ms | 804 KB | Output is correct |
13 | Correct | 733 ms | 720 KB | Output is correct |
14 | Correct | 6 ms | 344 KB | Output is correct |
15 | Correct | 9 ms | 344 KB | Output is correct |
16 | Correct | 34 ms | 344 KB | Output is correct |
17 | Correct | 94 ms | 600 KB | Output is correct |
18 | Correct | 104 ms | 604 KB | Output is correct |
19 | Correct | 253 ms | 852 KB | Output is correct |
20 | Correct | 251 ms | 604 KB | Output is correct |
21 | Correct | 791 ms | 920 KB | Output is correct |
22 | Correct | 767 ms | 796 KB | Output is correct |
23 | Correct | 727 ms | 720 KB | Output is correct |
24 | Correct | 682 ms | 724 KB | Output is correct |
25 | Correct | 10 ms | 340 KB | Output is correct |
26 | Correct | 7 ms | 344 KB | Output is correct |
27 | Correct | 20 ms | 344 KB | Output is correct |
28 | Correct | 17 ms | 344 KB | Output is correct |
29 | Correct | 25 ms | 344 KB | Output is correct |
30 | Correct | 162 ms | 736 KB | Output is correct |
31 | Correct | 153 ms | 704 KB | Output is correct |
32 | Correct | 158 ms | 700 KB | Output is correct |
33 | Correct | 262 ms | 344 KB | Output is correct |
34 | Correct | 282 ms | 532 KB | Output is correct |
35 | Correct | 274 ms | 592 KB | Output is correct |
36 | Correct | 736 ms | 716 KB | Output is correct |
37 | Correct | 685 ms | 712 KB | Output is correct |
38 | Correct | 671 ms | 720 KB | Output is correct |
39 | Correct | 708 ms | 720 KB | Output is correct |
40 | Correct | 746 ms | 724 KB | Output is correct |
41 | Correct | 676 ms | 748 KB | Output is correct |
42 | Correct | 696 ms | 748 KB | Output is correct |
43 | Correct | 674 ms | 1000 KB | Output is correct |
44 | Correct | 755 ms | 752 KB | Output is correct |
45 | Correct | 12 ms | 344 KB | Output is correct |
46 | Correct | 8 ms | 344 KB | Output is correct |
47 | Correct | 25 ms | 344 KB | Output is correct |
48 | Correct | 19 ms | 344 KB | Output is correct |
49 | Correct | 28 ms | 344 KB | Output is correct |
50 | Correct | 145 ms | 700 KB | Output is correct |
51 | Correct | 175 ms | 752 KB | Output is correct |
52 | Correct | 155 ms | 704 KB | Output is correct |
53 | Correct | 233 ms | 788 KB | Output is correct |
54 | Correct | 243 ms | 596 KB | Output is correct |
55 | Correct | 258 ms | 536 KB | Output is correct |
56 | Correct | 765 ms | 856 KB | Output is correct |
57 | Correct | 703 ms | 720 KB | Output is correct |
58 | Correct | 735 ms | 788 KB | Output is correct |
59 | Correct | 710 ms | 1020 KB | Output is correct |
60 | Correct | 721 ms | 764 KB | Output is correct |
61 | Correct | 648 ms | 788 KB | Output is correct |
62 | Correct | 757 ms | 788 KB | Output is correct |
63 | Correct | 715 ms | 764 KB | Output is correct |
64 | Correct | 783 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 20 ms | 344 KB | Output is correct |
3 | Partially correct | 127 ms | 852 KB | Output is partially correct |
4 | Partially correct | 316 ms | 588 KB | Output is partially correct |
5 | Partially correct | 697 ms | 724 KB | Output is partially correct |
6 | Correct | 7 ms | 344 KB | Output is correct |
7 | Correct | 23 ms | 852 KB | Output is correct |
8 | Partially correct | 135 ms | 344 KB | Output is partially correct |
9 | Partially correct | 236 ms | 548 KB | Output is partially correct |
10 | Partially correct | 759 ms | 716 KB | Output is partially correct |
11 | Partially correct | 700 ms | 856 KB | Output is partially correct |
12 | Partially correct | 625 ms | 720 KB | Output is partially correct |
13 | Partially correct | 748 ms | 720 KB | Output is partially correct |
14 | Correct | 6 ms | 344 KB | Output is correct |
15 | Correct | 10 ms | 344 KB | Output is correct |
16 | Correct | 38 ms | 344 KB | Output is correct |
17 | Partially correct | 79 ms | 600 KB | Output is partially correct |
18 | Partially correct | 116 ms | 856 KB | Output is partially correct |
19 | Partially correct | 253 ms | 612 KB | Output is partially correct |
20 | Partially correct | 229 ms | 796 KB | Output is partially correct |
21 | Correct | 12 ms | 344 KB | Output is correct |
22 | Correct | 8 ms | 344 KB | Output is correct |
23 | Correct | 30 ms | 344 KB | Output is correct |
24 | Correct | 25 ms | 344 KB | Output is correct |
25 | Correct | 18 ms | 344 KB | Output is correct |
26 | Partially correct | 162 ms | 512 KB | Output is partially correct |
27 | Partially correct | 156 ms | 696 KB | Output is partially correct |
28 | Partially correct | 166 ms | 444 KB | Output is partially correct |
29 | Partially correct | 273 ms | 536 KB | Output is partially correct |
30 | Partially correct | 227 ms | 344 KB | Output is partially correct |
31 | Partially correct | 233 ms | 536 KB | Output is partially correct |
32 | Correct | 10 ms | 344 KB | Output is correct |
33 | Correct | 7 ms | 344 KB | Output is correct |
34 | Correct | 23 ms | 344 KB | Output is correct |
35 | Correct | 21 ms | 344 KB | Output is correct |
36 | Correct | 20 ms | 344 KB | Output is correct |
37 | Partially correct | 157 ms | 712 KB | Output is partially correct |
38 | Partially correct | 148 ms | 700 KB | Output is partially correct |
39 | Partially correct | 159 ms | 700 KB | Output is partially correct |
40 | Partially correct | 242 ms | 848 KB | Output is partially correct |
41 | Partially correct | 257 ms | 592 KB | Output is partially correct |
42 | Partially correct | 246 ms | 560 KB | Output is partially correct |
43 | Partially correct | 695 ms | 792 KB | Output is partially correct |
44 | Partially correct | 670 ms | 792 KB | Output is partially correct |
45 | Partially correct | 717 ms | 716 KB | Output is partially correct |
46 | Partially correct | 693 ms | 724 KB | Output is partially correct |
47 | Partially correct | 677 ms | 720 KB | Output is partially correct |
48 | Partially correct | 663 ms | 716 KB | Output is partially correct |
49 | Partially correct | 755 ms | 720 KB | Output is partially correct |
50 | Partially correct | 689 ms | 956 KB | Output is partially correct |
51 | Partially correct | 714 ms | 716 KB | Output is partially correct |
52 | Partially correct | 664 ms | 856 KB | Output is partially correct |
53 | Partially correct | 724 ms | 848 KB | Output is partially correct |
54 | Partially correct | 677 ms | 752 KB | Output is partially correct |
55 | Partially correct | 686 ms | 748 KB | Output is partially correct |
56 | Partially correct | 716 ms | 720 KB | Output is partially correct |
57 | Partially correct | 773 ms | 856 KB | Output is partially correct |
58 | Partially correct | 656 ms | 716 KB | Output is partially correct |
59 | Partially correct | 700 ms | 948 KB | Output is partially correct |
60 | Partially correct | 675 ms | 752 KB | Output is partially correct |
61 | Partially correct | 744 ms | 748 KB | Output is partially correct |
62 | Partially correct | 672 ms | 716 KB | Output is partially correct |
63 | Partially correct | 736 ms | 716 KB | Output is partially correct |
64 | Partially correct | 791 ms | 856 KB | Output is partially correct |
65 | Partially correct | 675 ms | 784 KB | Output is partially correct |
66 | Partially correct | 681 ms | 764 KB | Output is partially correct |
67 | Partially correct | 761 ms | 784 KB | Output is partially correct |
68 | Partially correct | 681 ms | 780 KB | Output is partially correct |
69 | Partially correct | 730 ms | 752 KB | Output is partially correct |
70 | Partially correct | 666 ms | 960 KB | Output is partially correct |
71 | Partially correct | 719 ms | 1368 KB | Output is partially correct |
72 | Partially correct | 816 ms | 808 KB | Output is partially correct |
73 | Partially correct | 738 ms | 720 KB | Output is partially correct |
74 | Partially correct | 688 ms | 776 KB | Output is partially correct |
75 | Partially correct | 767 ms | 1112 KB | Output is partially correct |
76 | Partially correct | 684 ms | 1048 KB | Output is partially correct |
77 | Partially correct | 694 ms | 720 KB | Output is partially correct |
78 | Partially correct | 728 ms | 848 KB | Output is partially correct |
79 | Partially correct | 707 ms | 788 KB | Output is partially correct |
80 | Partially correct | 676 ms | 720 KB | Output is partially correct |
81 | Partially correct | 700 ms | 788 KB | Output is partially correct |
82 | Partially correct | 718 ms | 796 KB | Output is partially correct |