# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1079627 | 2024-08-28T19:11:39 Z | c2zi6 | Longest Trip (IOI23_longesttrip) | C++17 | 939 ms | 2080 KB |
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "longesttrip.h" int n; VVI gp; VVI edges; VI rev(VI a) { reverse(all(a)); return a; } VI longest_trip(int N, int D) { n = N; gp = VVI(n); edges = VVI(n, VI(n)); replr(i, 0, n-1) { replr(j, i+1, n-1) { if (are_connected({i}, {j})) { gp[i].pb(j); gp[j].pb(i); edges[i][j] = edges[j][i] = true; } } } VI path1; VI path2; path1.pb(0); path2.pb(1); replr(u, 2, n-1) { if (edges[path1.back()][u]) path1.pb(u); else if (edges[path2.back()][u]) path2.pb(u); else { for (int u : rev(path2)) path1.pb(u); path2 = VI{u}; } } if (edges[path2[0]][path1[0]]) { VI ans; for (int x : rev(path2)) ans.pb(x); for (int x : path1) ans.pb(x); return ans; } if (edges[path2.back()][path1[0]]) { VI ans; for (int x : path2) ans.pb(x); for (int x : path1) ans.pb(x); return ans; } if (edges[path1.back()][path2[0]]) { VI ans; for (int x : path1) ans.pb(x); for (int x : path2) ans.pb(x); return ans; } int ind1 = -1; int ind2 = -1; rep(i, path1.size()) { rep(j, path2.size()) { if (edges[path1[i]][path2[j]]) { ind1 = i; ind2 = j; break; } } } if (ind1 == -1) { if (path1.size() > path2.size()) return path1; return path2; } VI ans; replr(i, ind2+1, ind2+1 + path2.size()-1) { ans.pb(path2[i%(int)path2.size()]); } replr(i, ind1, ind1 + path1.size()-1) { ans.pb(path1[i%(int)path1.size()]); } return ans; }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 200 ms | 2080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 344 KB | Output is correct |
2 | Correct | 32 ms | 344 KB | Output is correct |
3 | Correct | 166 ms | 700 KB | Output is correct |
4 | Correct | 419 ms | 864 KB | Output is correct |
5 | Correct | 939 ms | 1104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 344 KB | Output is correct |
2 | Correct | 24 ms | 344 KB | Output is correct |
3 | Correct | 157 ms | 452 KB | Output is correct |
4 | Correct | 442 ms | 800 KB | Output is correct |
5 | Correct | 903 ms | 1376 KB | Output is correct |
6 | Correct | 9 ms | 344 KB | Output is correct |
7 | Correct | 18 ms | 344 KB | Output is correct |
8 | Correct | 161 ms | 592 KB | Output is correct |
9 | Correct | 361 ms | 796 KB | Output is correct |
10 | Correct | 901 ms | 1320 KB | Output is correct |
11 | Correct | 897 ms | 1360 KB | Output is correct |
12 | Correct | 870 ms | 1752 KB | Output is correct |
13 | Correct | 878 ms | 1272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 38 ms | 344 KB | Output is correct |
3 | Correct | 154 ms | 452 KB | Output is correct |
4 | Correct | 417 ms | 808 KB | Output is correct |
5 | Correct | 867 ms | 1400 KB | Output is correct |
6 | Correct | 9 ms | 344 KB | Output is correct |
7 | Correct | 21 ms | 344 KB | Output is correct |
8 | Correct | 158 ms | 592 KB | Output is correct |
9 | Correct | 345 ms | 800 KB | Output is correct |
10 | Correct | 819 ms | 1232 KB | Output is correct |
11 | Correct | 849 ms | 1276 KB | Output is correct |
12 | Correct | 886 ms | 1240 KB | Output is correct |
13 | Correct | 915 ms | 1040 KB | Output is correct |
14 | Correct | 8 ms | 344 KB | Output is correct |
15 | Correct | 16 ms | 344 KB | Output is correct |
16 | Correct | 40 ms | 344 KB | Output is correct |
17 | Correct | 116 ms | 344 KB | Output is correct |
18 | Correct | 145 ms | 688 KB | Output is correct |
19 | Correct | 272 ms | 752 KB | Output is correct |
20 | Correct | 335 ms | 592 KB | Output is correct |
21 | Correct | 834 ms | 1336 KB | Output is correct |
22 | Correct | 843 ms | 1244 KB | Output is correct |
23 | Correct | 862 ms | 1012 KB | Output is correct |
24 | Correct | 849 ms | 1448 KB | Output is correct |
25 | Correct | 9 ms | 344 KB | Output is correct |
26 | Correct | 10 ms | 344 KB | Output is correct |
27 | Correct | 20 ms | 344 KB | Output is correct |
28 | Correct | 24 ms | 344 KB | Output is correct |
29 | Correct | 30 ms | 344 KB | Output is correct |
30 | Correct | 179 ms | 464 KB | Output is correct |
31 | Correct | 201 ms | 592 KB | Output is correct |
32 | Correct | 213 ms | 600 KB | Output is correct |
33 | Correct | 314 ms | 592 KB | Output is correct |
34 | Correct | 309 ms | 856 KB | Output is correct |
35 | Correct | 321 ms | 536 KB | Output is correct |
36 | Correct | 842 ms | 1184 KB | Output is correct |
37 | Correct | 862 ms | 1240 KB | Output is correct |
38 | Correct | 800 ms | 1260 KB | Output is correct |
39 | Correct | 857 ms | 1236 KB | Output is correct |
40 | Correct | 819 ms | 1112 KB | Output is correct |
41 | Correct | 800 ms | 1048 KB | Output is correct |
42 | Correct | 764 ms | 992 KB | Output is correct |
43 | Correct | 801 ms | 1084 KB | Output is correct |
44 | Correct | 819 ms | 1080 KB | Output is correct |
45 | Correct | 9 ms | 344 KB | Output is correct |
46 | Correct | 14 ms | 344 KB | Output is correct |
47 | Correct | 23 ms | 344 KB | Output is correct |
48 | Correct | 22 ms | 344 KB | Output is correct |
49 | Correct | 22 ms | 344 KB | Output is correct |
50 | Correct | 185 ms | 472 KB | Output is correct |
51 | Correct | 179 ms | 460 KB | Output is correct |
52 | Correct | 186 ms | 460 KB | Output is correct |
53 | Correct | 291 ms | 532 KB | Output is correct |
54 | Correct | 291 ms | 540 KB | Output is correct |
55 | Correct | 307 ms | 344 KB | Output is correct |
56 | Correct | 844 ms | 1120 KB | Output is correct |
57 | Correct | 816 ms | 1496 KB | Output is correct |
58 | Correct | 817 ms | 1292 KB | Output is correct |
59 | Correct | 860 ms | 1228 KB | Output is correct |
60 | Correct | 861 ms | 1984 KB | Output is correct |
61 | Correct | 859 ms | 1204 KB | Output is correct |
62 | Correct | 853 ms | 1228 KB | Output is correct |
63 | Correct | 918 ms | 1212 KB | Output is correct |
64 | Correct | 831 ms | 1000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 344 KB | Output is correct |
2 | Correct | 29 ms | 344 KB | Output is correct |
3 | Partially correct | 152 ms | 448 KB | Output is partially correct |
4 | Partially correct | 416 ms | 576 KB | Output is partially correct |
5 | Partially correct | 848 ms | 1112 KB | Output is partially correct |
6 | Correct | 11 ms | 344 KB | Output is correct |
7 | Correct | 22 ms | 344 KB | Output is correct |
8 | Partially correct | 160 ms | 592 KB | Output is partially correct |
9 | Partially correct | 316 ms | 788 KB | Output is partially correct |
10 | Partially correct | 867 ms | 1088 KB | Output is partially correct |
11 | Partially correct | 848 ms | 1216 KB | Output is partially correct |
12 | Partially correct | 816 ms | 1244 KB | Output is partially correct |
13 | Partially correct | 873 ms | 1284 KB | Output is partially correct |
14 | Correct | 7 ms | 344 KB | Output is correct |
15 | Correct | 11 ms | 344 KB | Output is correct |
16 | Correct | 46 ms | 344 KB | Output is correct |
17 | Partially correct | 94 ms | 344 KB | Output is partially correct |
18 | Partially correct | 140 ms | 344 KB | Output is partially correct |
19 | Partially correct | 286 ms | 344 KB | Output is partially correct |
20 | Partially correct | 320 ms | 788 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 | 18 ms | 344 KB | Output is correct |
24 | Correct | 18 ms | 344 KB | Output is correct |
25 | Correct | 26 ms | 344 KB | Output is correct |
26 | Partially correct | 182 ms | 464 KB | Output is partially correct |
27 | Partially correct | 199 ms | 708 KB | Output is partially correct |
28 | Partially correct | 195 ms | 600 KB | Output is partially correct |
29 | Partially correct | 290 ms | 540 KB | Output is partially correct |
30 | Partially correct | 331 ms | 1020 KB | Output is partially correct |
31 | Partially correct | 357 ms | 1008 KB | Output is partially correct |
32 | Correct | 11 ms | 344 KB | Output is correct |
33 | Correct | 9 ms | 344 KB | Output is correct |
34 | Correct | 32 ms | 344 KB | Output is correct |
35 | Correct | 35 ms | 344 KB | Output is correct |
36 | Correct | 30 ms | 344 KB | Output is correct |
37 | Partially correct | 199 ms | 592 KB | Output is partially correct |
38 | Partially correct | 197 ms | 344 KB | Output is partially correct |
39 | Partially correct | 215 ms | 596 KB | Output is partially correct |
40 | Partially correct | 329 ms | 528 KB | Output is partially correct |
41 | Partially correct | 323 ms | 592 KB | Output is partially correct |
42 | Partially correct | 314 ms | 988 KB | Output is partially correct |
43 | Partially correct | 833 ms | 1504 KB | Output is partially correct |
44 | Partially correct | 795 ms | 1312 KB | Output is partially correct |
45 | Partially correct | 843 ms | 1264 KB | Output is partially correct |
46 | Partially correct | 833 ms | 1028 KB | Output is partially correct |
47 | Partially correct | 783 ms | 1124 KB | Output is partially correct |
48 | Partially correct | 857 ms | 1004 KB | Output is partially correct |
49 | Partially correct | 901 ms | 1220 KB | Output is partially correct |
50 | Partially correct | 819 ms | 1368 KB | Output is partially correct |
51 | Partially correct | 804 ms | 1176 KB | Output is partially correct |
52 | Partially correct | 867 ms | 1052 KB | Output is partially correct |
53 | Partially correct | 849 ms | 1152 KB | Output is partially correct |
54 | Partially correct | 858 ms | 1324 KB | Output is partially correct |
55 | Partially correct | 810 ms | 1748 KB | Output is partially correct |
56 | Partially correct | 871 ms | 1360 KB | Output is partially correct |
57 | Partially correct | 873 ms | 1568 KB | Output is partially correct |
58 | Partially correct | 833 ms | 1608 KB | Output is partially correct |
59 | Partially correct | 883 ms | 1084 KB | Output is partially correct |
60 | Partially correct | 826 ms | 1144 KB | Output is partially correct |
61 | Partially correct | 843 ms | 1232 KB | Output is partially correct |
62 | Partially correct | 823 ms | 1372 KB | Output is partially correct |
63 | Partially correct | 921 ms | 976 KB | Output is partially correct |
64 | Partially correct | 845 ms | 1204 KB | Output is partially correct |
65 | Partially correct | 863 ms | 1124 KB | Output is partially correct |
66 | Partially correct | 857 ms | 1292 KB | Output is partially correct |
67 | Partially correct | 862 ms | 1516 KB | Output is partially correct |
68 | Partially correct | 869 ms | 1356 KB | Output is partially correct |
69 | Partially correct | 839 ms | 1540 KB | Output is partially correct |
70 | Partially correct | 892 ms | 1272 KB | Output is partially correct |
71 | Partially correct | 856 ms | 1608 KB | Output is partially correct |
72 | Partially correct | 858 ms | 1080 KB | Output is partially correct |
73 | Partially correct | 835 ms | 1512 KB | Output is partially correct |
74 | Partially correct | 878 ms | 1332 KB | Output is partially correct |
75 | Partially correct | 826 ms | 1280 KB | Output is partially correct |
76 | Partially correct | 853 ms | 1240 KB | Output is partially correct |
77 | Partially correct | 844 ms | 1112 KB | Output is partially correct |
78 | Partially correct | 824 ms | 1136 KB | Output is partially correct |
79 | Partially correct | 832 ms | 1240 KB | Output is partially correct |
80 | Partially correct | 848 ms | 1480 KB | Output is partially correct |
81 | Partially correct | 875 ms | 1256 KB | Output is partially correct |
82 | Partially correct | 837 ms | 1264 KB | Output is partially correct |