# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046226 | 2024-08-06T11:54:50 Z | RecursiveCo | Longest Trip (IOI23_longesttrip) | C++17 | 769 ms | 596 KB |
// CF template, version 3.0 #include <bits/stdc++.h> #include "longesttrip.h" using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} //#define int long long int template <typename T, typename I> struct segtree { int n; vector<T> tree; vector<I> initial; T id; segtree(int i_n, vector<I> i_initial, T i_id): n(i_n), initial(i_initial), id(i_id) { tree.resize(4 * n); } T conquer(T left, T right) { // write your conquer function } T value(I inp) { // write your value function } void build(int v, int l, int r) { if (l == r) tree[v] = value(initial[l]); else { int middle = (l + r) / 2; build(2 * v, l, middle); build(2 * v + 1, middle + 1, r); tree[v] = conquer(tree[2 * v], tree[2 * v + 1]); } } void upd(int v, int l, int r, int i, I x) { if (l == r) tree[v] = value(x); else { int middle = (l + r) / 2; if (middle >= i) upd(2 * v, l, middle, i, x); else upd(2 * v + 1, middle + 1, r, i, x); tree[v] = conquer(tree[2 * v], tree[2 * v + 1]); } } T query(int v, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return tree[v]; else if (r < ql || qr < l) return id; int middle = (l + r) / 2; T left = query(2 * v, l, middle, ql, qr); T right = query(2 * v + 1, middle + 1, r, ql, qr); return conquer(left, right); } }; // vector<int> vector<int> parent; int find(int v) { if (v == parent[v]) return v; return parent[v] = find(parent[v]); } void unite(int a, int b) { a = find(a); b = find(b); parent[a] = b; } vector<int> longest_trip(int N, int _D) { vector<vector<bool>> adjMatrix(N, vector<bool>(N, false)); vector<int> path; vector<int> other(N, true); parent.clear(); forto(N, i) parent.push_back(i); forto(N, i) { vector<int> A; A.push_back(i); for (int j = i + 1; j < N; j++) { vector<int> B; B.push_back(j); bool edge = are_connected(A, B); if (edge) { unite(i, j); adjMatrix[i][j] = adjMatrix[j][i] = true; if (path.empty()) path.push_back(i), path.push_back(j), other[i] = other[j] = false; } } } bool connected = true; forto(N, i) if (find(i) != find(0)) connected = false; if (!connected) { vector<int> one; vector<int> two; forto(N, i) { if (find(i) == find(0)) one.push_back(i); else two.push_back(i); } if (one.size() > two.size()) swap(one, two); return two; } vector<int> newpath; while (path.size() < N) { int s = path.size(); newpath.clear(); if (adjMatrix[path[0]][path[s - 1]]) { forto(N, i) { if (!other[i]) continue; int j = 0; bool found = false; for (int p: path) { if (adjMatrix[i][p]) { other[i] = false; found = true; newpath.push_back(i); for (int k = j; k < s; k++) newpath.push_back(path[k]); forto(j, k) newpath.push_back(path[k]); swap(path, newpath); break; } j++; } if (found) break; } } else { forto(N, i) { if (!other[i]) continue; if (adjMatrix[i][path[0]]) { rev(path); path.push_back(i); other[i] = false; break; } if (adjMatrix[i][path[s - 1]]) { path.push_back(i); other[i] = false; break; } } } } return path; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 176 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 19 ms | 344 KB | Output is correct |
3 | Correct | 128 ms | 344 KB | Output is correct |
4 | Correct | 366 ms | 344 KB | Output is correct |
5 | Correct | 769 ms | 440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 344 KB | Output is correct |
2 | Correct | 18 ms | 344 KB | Output is correct |
3 | Correct | 126 ms | 344 KB | Output is correct |
4 | Correct | 372 ms | 596 KB | Output is correct |
5 | Correct | 691 ms | 344 KB | Output is correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 22 ms | 344 KB | Output is correct |
8 | Correct | 127 ms | 344 KB | Output is correct |
9 | Correct | 260 ms | 592 KB | Output is correct |
10 | Correct | 681 ms | 592 KB | Output is correct |
11 | Correct | 681 ms | 592 KB | Output is correct |
12 | Correct | 756 ms | 592 KB | Output is correct |
13 | Correct | 695 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 17 ms | 344 KB | Output is correct |
3 | Correct | 130 ms | 344 KB | Output is correct |
4 | Correct | 322 ms | 344 KB | Output is correct |
5 | Correct | 697 ms | 436 KB | Output is correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 18 ms | 344 KB | Output is correct |
8 | Correct | 104 ms | 344 KB | Output is correct |
9 | Correct | 262 ms | 344 KB | Output is correct |
10 | Correct | 701 ms | 436 KB | Output is correct |
11 | Correct | 660 ms | 432 KB | Output is correct |
12 | Correct | 721 ms | 596 KB | Output is correct |
13 | Correct | 670 ms | 436 KB | Output is correct |
14 | Correct | 6 ms | 344 KB | Output is correct |
15 | Correct | 9 ms | 344 KB | Output is correct |
16 | Correct | 35 ms | 344 KB | Output is correct |
17 | Correct | 83 ms | 344 KB | Output is correct |
18 | Correct | 130 ms | 344 KB | Output is correct |
19 | Correct | 304 ms | 592 KB | Output is correct |
20 | Correct | 263 ms | 592 KB | Output is correct |
21 | Correct | 705 ms | 436 KB | Output is correct |
22 | Correct | 681 ms | 432 KB | Output is correct |
23 | Correct | 663 ms | 436 KB | Output is correct |
24 | Correct | 710 ms | 432 KB | Output is correct |
25 | Correct | 11 ms | 344 KB | Output is correct |
26 | Correct | 7 ms | 344 KB | Output is correct |
27 | Correct | 18 ms | 344 KB | Output is correct |
28 | Correct | 18 ms | 344 KB | Output is correct |
29 | Correct | 17 ms | 344 KB | Output is correct |
30 | Correct | 179 ms | 344 KB | Output is correct |
31 | Correct | 168 ms | 344 KB | Output is correct |
32 | Correct | 175 ms | 344 KB | Output is correct |
33 | Correct | 289 ms | 344 KB | Output is correct |
34 | Correct | 257 ms | 344 KB | Output is correct |
35 | Correct | 279 ms | 344 KB | Output is correct |
36 | Correct | 702 ms | 440 KB | Output is correct |
37 | Correct | 755 ms | 592 KB | Output is correct |
38 | Correct | 714 ms | 436 KB | Output is correct |
39 | Correct | 740 ms | 436 KB | Output is correct |
40 | Correct | 715 ms | 432 KB | Output is correct |
41 | Correct | 708 ms | 592 KB | Output is correct |
42 | Correct | 697 ms | 436 KB | Output is correct |
43 | Correct | 709 ms | 436 KB | Output is correct |
44 | Correct | 687 ms | 440 KB | Output is correct |
45 | Correct | 5 ms | 344 KB | Output is correct |
46 | Correct | 7 ms | 344 KB | Output is correct |
47 | Correct | 18 ms | 344 KB | Output is correct |
48 | Correct | 19 ms | 344 KB | Output is correct |
49 | Correct | 24 ms | 344 KB | Output is correct |
50 | Correct | 175 ms | 344 KB | Output is correct |
51 | Correct | 149 ms | 344 KB | Output is correct |
52 | Correct | 170 ms | 344 KB | Output is correct |
53 | Correct | 278 ms | 344 KB | Output is correct |
54 | Correct | 241 ms | 344 KB | Output is correct |
55 | Correct | 241 ms | 344 KB | Output is correct |
56 | Correct | 723 ms | 436 KB | Output is correct |
57 | Correct | 692 ms | 432 KB | Output is correct |
58 | Correct | 751 ms | 436 KB | Output is correct |
59 | Correct | 709 ms | 436 KB | Output is correct |
60 | Correct | 720 ms | 432 KB | Output is correct |
61 | Correct | 728 ms | 432 KB | Output is correct |
62 | Correct | 702 ms | 592 KB | Output is correct |
63 | Correct | 718 ms | 592 KB | Output is correct |
64 | Correct | 749 ms | 432 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 340 KB | Output is correct |
2 | Correct | 18 ms | 344 KB | Output is correct |
3 | Partially correct | 118 ms | 344 KB | Output is partially correct |
4 | Partially correct | 342 ms | 344 KB | Output is partially correct |
5 | Partially correct | 662 ms | 432 KB | Output is partially correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Correct | 24 ms | 344 KB | Output is correct |
8 | Partially correct | 140 ms | 344 KB | Output is partially correct |
9 | Partially correct | 273 ms | 416 KB | Output is partially correct |
10 | Partially correct | 671 ms | 432 KB | Output is partially correct |
11 | Partially correct | 631 ms | 436 KB | Output is partially correct |
12 | Partially correct | 718 ms | 436 KB | Output is partially correct |
13 | Partially correct | 737 ms | 440 KB | Output is partially correct |
14 | Correct | 4 ms | 596 KB | Output is correct |
15 | Correct | 13 ms | 344 KB | Output is correct |
16 | Correct | 30 ms | 344 KB | Output is correct |
17 | Partially correct | 65 ms | 344 KB | Output is partially correct |
18 | Partially correct | 144 ms | 344 KB | Output is partially correct |
19 | Partially correct | 237 ms | 592 KB | Output is partially correct |
20 | Partially correct | 271 ms | 420 KB | Output is partially correct |
21 | Correct | 5 ms | 344 KB | Output is correct |
22 | Correct | 7 ms | 344 KB | Output is correct |
23 | Correct | 16 ms | 344 KB | Output is correct |
24 | Correct | 17 ms | 344 KB | Output is correct |
25 | Correct | 20 ms | 344 KB | Output is correct |
26 | Partially correct | 156 ms | 344 KB | Output is partially correct |
27 | Partially correct | 137 ms | 344 KB | Output is partially correct |
28 | Partially correct | 162 ms | 344 KB | Output is partially correct |
29 | Partially correct | 256 ms | 344 KB | Output is partially correct |
30 | Partially correct | 238 ms | 344 KB | Output is partially correct |
31 | Partially correct | 246 ms | 344 KB | Output is partially correct |
32 | Correct | 7 ms | 344 KB | Output is correct |
33 | Correct | 9 ms | 344 KB | Output is correct |
34 | Correct | 22 ms | 344 KB | Output is correct |
35 | Correct | 19 ms | 344 KB | Output is correct |
36 | Correct | 15 ms | 344 KB | Output is correct |
37 | Partially correct | 158 ms | 344 KB | Output is partially correct |
38 | Partially correct | 179 ms | 344 KB | Output is partially correct |
39 | Partially correct | 163 ms | 344 KB | Output is partially correct |
40 | Partially correct | 266 ms | 592 KB | Output is partially correct |
41 | Partially correct | 255 ms | 420 KB | Output is partially correct |
42 | Partially correct | 285 ms | 424 KB | Output is partially correct |
43 | Partially correct | 661 ms | 436 KB | Output is partially correct |
44 | Partially correct | 695 ms | 436 KB | Output is partially correct |
45 | Partially correct | 672 ms | 432 KB | Output is partially correct |
46 | Partially correct | 711 ms | 436 KB | Output is partially correct |
47 | Partially correct | 709 ms | 432 KB | Output is partially correct |
48 | Partially correct | 690 ms | 592 KB | Output is partially correct |
49 | Partially correct | 717 ms | 440 KB | Output is partially correct |
50 | Partially correct | 723 ms | 440 KB | Output is partially correct |
51 | Partially correct | 713 ms | 436 KB | Output is partially correct |
52 | Partially correct | 677 ms | 436 KB | Output is partially correct |
53 | Partially correct | 681 ms | 436 KB | Output is partially correct |
54 | Partially correct | 737 ms | 436 KB | Output is partially correct |
55 | Partially correct | 668 ms | 440 KB | Output is partially correct |
56 | Partially correct | 665 ms | 596 KB | Output is partially correct |
57 | Partially correct | 727 ms | 432 KB | Output is partially correct |
58 | Partially correct | 684 ms | 436 KB | Output is partially correct |
59 | Partially correct | 670 ms | 440 KB | Output is partially correct |
60 | Partially correct | 722 ms | 432 KB | Output is partially correct |
61 | Partially correct | 683 ms | 432 KB | Output is partially correct |
62 | Partially correct | 682 ms | 440 KB | Output is partially correct |
63 | Partially correct | 726 ms | 440 KB | Output is partially correct |
64 | Partially correct | 666 ms | 432 KB | Output is partially correct |
65 | Partially correct | 670 ms | 436 KB | Output is partially correct |
66 | Partially correct | 702 ms | 436 KB | Output is partially correct |
67 | Partially correct | 699 ms | 432 KB | Output is partially correct |
68 | Partially correct | 677 ms | 436 KB | Output is partially correct |
69 | Partially correct | 700 ms | 436 KB | Output is partially correct |
70 | Partially correct | 691 ms | 436 KB | Output is partially correct |
71 | Partially correct | 690 ms | 432 KB | Output is partially correct |
72 | Partially correct | 682 ms | 592 KB | Output is partially correct |
73 | Partially correct | 726 ms | 432 KB | Output is partially correct |
74 | Partially correct | 647 ms | 444 KB | Output is partially correct |
75 | Partially correct | 699 ms | 432 KB | Output is partially correct |
76 | Partially correct | 719 ms | 436 KB | Output is partially correct |
77 | Partially correct | 700 ms | 436 KB | Output is partially correct |
78 | Partially correct | 674 ms | 432 KB | Output is partially correct |
79 | Partially correct | 722 ms | 592 KB | Output is partially correct |
80 | Partially correct | 700 ms | 436 KB | Output is partially correct |
81 | Partially correct | 737 ms | 436 KB | Output is partially correct |
82 | Partially correct | 694 ms | 436 KB | Output is partially correct |