# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088000 | 2024-09-13T16:41:29 Z | Valaki2 | Longest Trip (IOI23_longesttrip) | C++17 | 892 ms | 1112 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; #define pb push_back const int maxn = 256; int n; int edge[maxn][maxn]; void getedges() { for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { int val = are_connected({i}, {j}); edge[i][j] = edge[j][i] = val; } } } bool vis[maxn]; void reset() { for(int i = 0; i < n; i++) { vis[i] = false; for(int j = 0; j < n; j++) { edge[i][j] = 0; } } } void insert_at(vector<int> &path, int x, int y) { /*vis[y] = true; path.pb(-1); for(int i = path.size(); i >= 1; i--) { if(path[i - 1] == x) { path[i] = y; break; } else { path[i] = path[i - 1]; } }*/ vis[y] = true; vector<int> a, b; for(int i = 0; i < path.size(); i++) { if(path[i] == x) { a = path; a.resize(i + 1); a.pb(y); for(int j = i + 1; j < path.size(); j++) { b.pb(path[j]); } break; } } path.clear(); for(int cur : b) { path.pb(cur); } for(int cur : a) { path.pb(cur); } } bool iterate(vector<int> &path) { for(int i = 0; i < n; i++) { if(vis[i]) { continue; } if(edge[i][path[0]]) { reverse(path.begin(), path.end()); path.pb(i); vis[i] = true; reverse(path.begin(), path.end()); return true; } if(edge[i][path.back()]) { path.pb(i); vis[i] = true; return true; } } for(int x : path) { for(int y = 0; y < n; y++) { if(vis[y]) { continue; } if(edge[x][y]) { insert_at(path, x, y); return true; } } } return false; } vector<int> longest_trip(int N, int D){ reset(); n = N; getedges(); vector<int> path = {0}; vis[0] = true; while(path.size() < n) { bool isgood = iterate(path); if(!isgood) { if(path.size() > n - path.size()) { return path; } else { path.clear(); for(int i = 0; i < n; i++) { if(!vis[i]) { path.pb(i); } } return path; } } } return path; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 183 ms | 672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 344 KB | Output is correct |
2 | Correct | 22 ms | 344 KB | Output is correct |
3 | Correct | 141 ms | 344 KB | Output is correct |
4 | Correct | 433 ms | 344 KB | Output is correct |
5 | Correct | 826 ms | 672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 22 ms | 344 KB | Output is correct |
3 | Correct | 155 ms | 344 KB | Output is correct |
4 | Correct | 410 ms | 344 KB | Output is correct |
5 | Correct | 855 ms | 672 KB | Output is correct |
6 | Correct | 5 ms | 344 KB | Output is correct |
7 | Correct | 24 ms | 344 KB | Output is correct |
8 | Correct | 150 ms | 344 KB | Output is correct |
9 | Correct | 315 ms | 344 KB | Output is correct |
10 | Correct | 846 ms | 692 KB | Output is correct |
11 | Correct | 814 ms | 676 KB | Output is correct |
12 | Correct | 833 ms | 600 KB | Output is correct |
13 | Correct | 833 ms | 672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 344 KB | Output is correct |
2 | Correct | 20 ms | 344 KB | Output is correct |
3 | Correct | 177 ms | 344 KB | Output is correct |
4 | Correct | 402 ms | 344 KB | Output is correct |
5 | Correct | 738 ms | 668 KB | Output is correct |
6 | Correct | 5 ms | 344 KB | Output is correct |
7 | Correct | 22 ms | 344 KB | Output is correct |
8 | Correct | 162 ms | 344 KB | Output is correct |
9 | Correct | 288 ms | 344 KB | Output is correct |
10 | Correct | 850 ms | 676 KB | Output is correct |
11 | Correct | 816 ms | 668 KB | Output is correct |
12 | Correct | 863 ms | 668 KB | Output is correct |
13 | Correct | 777 ms | 688 KB | Output is correct |
14 | Correct | 7 ms | 344 KB | Output is correct |
15 | Correct | 12 ms | 344 KB | Output is correct |
16 | Correct | 57 ms | 344 KB | Output is correct |
17 | Correct | 83 ms | 344 KB | Output is correct |
18 | Correct | 160 ms | 344 KB | Output is correct |
19 | Correct | 269 ms | 344 KB | Output is correct |
20 | Correct | 288 ms | 344 KB | Output is correct |
21 | Correct | 815 ms | 672 KB | Output is correct |
22 | Correct | 793 ms | 672 KB | Output is correct |
23 | Correct | 810 ms | 672 KB | Output is correct |
24 | Correct | 807 ms | 668 KB | Output is correct |
25 | Correct | 8 ms | 344 KB | Output is correct |
26 | Correct | 6 ms | 344 KB | Output is correct |
27 | Correct | 25 ms | 344 KB | Output is correct |
28 | Correct | 22 ms | 344 KB | Output is correct |
29 | Correct | 22 ms | 344 KB | Output is correct |
30 | Correct | 187 ms | 344 KB | Output is correct |
31 | Correct | 198 ms | 344 KB | Output is correct |
32 | Correct | 193 ms | 344 KB | Output is correct |
33 | Correct | 313 ms | 344 KB | Output is correct |
34 | Correct | 301 ms | 344 KB | Output is correct |
35 | Correct | 293 ms | 344 KB | Output is correct |
36 | Correct | 809 ms | 668 KB | Output is correct |
37 | Correct | 761 ms | 672 KB | Output is correct |
38 | Correct | 860 ms | 672 KB | Output is correct |
39 | Correct | 851 ms | 668 KB | Output is correct |
40 | Correct | 867 ms | 676 KB | Output is correct |
41 | Correct | 881 ms | 600 KB | Output is correct |
42 | Correct | 847 ms | 600 KB | Output is correct |
43 | Correct | 807 ms | 672 KB | Output is correct |
44 | Correct | 855 ms | 668 KB | Output is correct |
45 | Correct | 10 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 | 15 ms | 344 KB | Output is correct |
49 | Correct | 15 ms | 344 KB | Output is correct |
50 | Correct | 188 ms | 344 KB | Output is correct |
51 | Correct | 199 ms | 344 KB | Output is correct |
52 | Correct | 203 ms | 344 KB | Output is correct |
53 | Correct | 295 ms | 344 KB | Output is correct |
54 | Correct | 353 ms | 340 KB | Output is correct |
55 | Correct | 322 ms | 344 KB | Output is correct |
56 | Correct | 833 ms | 676 KB | Output is correct |
57 | Correct | 798 ms | 668 KB | Output is correct |
58 | Correct | 801 ms | 600 KB | Output is correct |
59 | Correct | 806 ms | 672 KB | Output is correct |
60 | Correct | 795 ms | 668 KB | Output is correct |
61 | Correct | 841 ms | 668 KB | Output is correct |
62 | Correct | 828 ms | 668 KB | Output is correct |
63 | Correct | 858 ms | 668 KB | Output is correct |
64 | Correct | 802 ms | 676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 21 ms | 344 KB | Output is correct |
3 | Partially correct | 135 ms | 344 KB | Output is partially correct |
4 | Partially correct | 384 ms | 344 KB | Output is partially correct |
5 | Partially correct | 800 ms | 672 KB | Output is partially correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 29 ms | 344 KB | Output is correct |
8 | Partially correct | 155 ms | 600 KB | Output is partially correct |
9 | Partially correct | 336 ms | 344 KB | Output is partially correct |
10 | Partially correct | 860 ms | 672 KB | Output is partially correct |
11 | Partially correct | 833 ms | 676 KB | Output is partially correct |
12 | Partially correct | 786 ms | 848 KB | Output is partially correct |
13 | Partially correct | 820 ms | 672 KB | Output is partially correct |
14 | Correct | 4 ms | 344 KB | Output is correct |
15 | Correct | 9 ms | 344 KB | Output is correct |
16 | Correct | 40 ms | 344 KB | Output is correct |
17 | Partially correct | 98 ms | 344 KB | Output is partially correct |
18 | Partially correct | 161 ms | 344 KB | Output is partially correct |
19 | Partially correct | 302 ms | 772 KB | Output is partially correct |
20 | Partially correct | 309 ms | 344 KB | Output is partially correct |
21 | Correct | 10 ms | 344 KB | Output is correct |
22 | Correct | 9 ms | 344 KB | Output is correct |
23 | Correct | 25 ms | 344 KB | Output is correct |
24 | Correct | 30 ms | 344 KB | Output is correct |
25 | Correct | 24 ms | 344 KB | Output is correct |
26 | Partially correct | 173 ms | 344 KB | Output is partially correct |
27 | Partially correct | 195 ms | 344 KB | Output is partially correct |
28 | Partially correct | 195 ms | 748 KB | Output is partially correct |
29 | Partially correct | 327 ms | 344 KB | Output is partially correct |
30 | Partially correct | 320 ms | 344 KB | Output is partially correct |
31 | Partially correct | 304 ms | 344 KB | Output is partially correct |
32 | Correct | 9 ms | 344 KB | Output is correct |
33 | Correct | 10 ms | 344 KB | Output is correct |
34 | Correct | 21 ms | 344 KB | Output is correct |
35 | Correct | 21 ms | 344 KB | Output is correct |
36 | Correct | 24 ms | 344 KB | Output is correct |
37 | Partially correct | 198 ms | 344 KB | Output is partially correct |
38 | Partially correct | 198 ms | 344 KB | Output is partially correct |
39 | Partially correct | 204 ms | 600 KB | Output is partially correct |
40 | Partially correct | 290 ms | 344 KB | Output is partially correct |
41 | Partially correct | 318 ms | 344 KB | Output is partially correct |
42 | Partially correct | 276 ms | 596 KB | Output is partially correct |
43 | Partially correct | 881 ms | 672 KB | Output is partially correct |
44 | Partially correct | 814 ms | 676 KB | Output is partially correct |
45 | Partially correct | 837 ms | 672 KB | Output is partially correct |
46 | Partially correct | 892 ms | 668 KB | Output is partially correct |
47 | Partially correct | 847 ms | 856 KB | Output is partially correct |
48 | Partially correct | 864 ms | 672 KB | Output is partially correct |
49 | Partially correct | 818 ms | 668 KB | Output is partially correct |
50 | Partially correct | 886 ms | 668 KB | Output is partially correct |
51 | Partially correct | 806 ms | 672 KB | Output is partially correct |
52 | Partially correct | 842 ms | 600 KB | Output is partially correct |
53 | Partially correct | 859 ms | 600 KB | Output is partially correct |
54 | Partially correct | 845 ms | 676 KB | Output is partially correct |
55 | Partially correct | 853 ms | 672 KB | Output is partially correct |
56 | Partially correct | 794 ms | 668 KB | Output is partially correct |
57 | Partially correct | 846 ms | 672 KB | Output is partially correct |
58 | Partially correct | 809 ms | 668 KB | Output is partially correct |
59 | Partially correct | 849 ms | 672 KB | Output is partially correct |
60 | Partially correct | 865 ms | 600 KB | Output is partially correct |
61 | Partially correct | 760 ms | 600 KB | Output is partially correct |
62 | Partially correct | 798 ms | 676 KB | Output is partially correct |
63 | Partially correct | 812 ms | 848 KB | Output is partially correct |
64 | Partially correct | 833 ms | 676 KB | Output is partially correct |
65 | Partially correct | 797 ms | 676 KB | Output is partially correct |
66 | Partially correct | 889 ms | 672 KB | Output is partially correct |
67 | Partially correct | 782 ms | 668 KB | Output is partially correct |
68 | Partially correct | 870 ms | 600 KB | Output is partially correct |
69 | Partially correct | 852 ms | 668 KB | Output is partially correct |
70 | Partially correct | 835 ms | 672 KB | Output is partially correct |
71 | Partially correct | 809 ms | 672 KB | Output is partially correct |
72 | Partially correct | 821 ms | 676 KB | Output is partially correct |
73 | Partially correct | 819 ms | 668 KB | Output is partially correct |
74 | Partially correct | 852 ms | 672 KB | Output is partially correct |
75 | Partially correct | 818 ms | 672 KB | Output is partially correct |
76 | Partially correct | 815 ms | 1112 KB | Output is partially correct |
77 | Partially correct | 805 ms | 672 KB | Output is partially correct |
78 | Partially correct | 838 ms | 672 KB | Output is partially correct |
79 | Partially correct | 878 ms | 672 KB | Output is partially correct |
80 | Partially correct | 834 ms | 668 KB | Output is partially correct |
81 | Partially correct | 842 ms | 668 KB | Output is partially correct |
82 | Partially correct | 823 ms | 668 KB | Output is partially correct |