#include "longesttrip.h"
#include "bits/stdc++.h"
using namespace std;
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define inf 1000'000'000'000'000'000LL
#define bit(x, i) (((x) >> i) & 1)
template<typename T>
using vec = vector<T>;
std::vector<int> longest_trip(int n, int d) {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
if (d == 3) {
vec<int> ans(n);
iota(all(ans), 0);
return ans;
}
if (d == 2) {
deque<int> ans;
int cur = 0;
ans.push_back(cur);
set<int> not_used;
for (int i = 1; i < n; i++) {
not_used.insert(i);
}
while (true) {
if (not_used.empty()) break;
vec<int> next(all(not_used));
int nxt = next[0];
if (are_connected({cur}, {nxt})) {
ans.push_back(nxt);
not_used.erase(nxt);
cur = nxt;
} else {
if (next.size() == 1) {
ans.push_front(next[0]);
break;
} else {
int net = next[1];
ans.push_back(net);
not_used.erase(net);
cur = net;
}
}
}
return vec<int>(all(ans));
} else {
int ct = 0;
int border = n * 1300;
auto attempt = [&]() {
deque<int> ans;
int cur = rnd() % n;
ans.push_back(cur);
set<int> not_used;
for (int i = 0; i < n; i++) {
if (i != cur) not_used.insert(i);
}
auto try_find = [&](int v) {
vec<int> t(all(not_used));
ct += len(t) + 1;
if (!are_connected({v}, t)) return -1;
shuffle(all(t), rnd);
int tl = 0;
int tr = len(t) - 1;
auto get_part = [&](int f) {
vec<int> r;
for (int i = 0; i <= f; i++)
r.push_back(t[i]);
return r;
};
while (tl != tr) {
int tm = (tl + tr) / 2;
ct += len(get_part(tm)) + 1;
if (are_connected({v}, get_part(tm))) {
tr = tm;
} else {
tl = tm + 1;
}
}
return t[tl];
};
while (true) {
if (not_used.empty()) break;
int u = try_find(ans.back());
if (u == -1) break;
ans.push_back(u);
not_used.erase(u);
}
while (true) {
if (not_used.empty()) break;
int u = try_find(ans.front());
if (u == -1) break;
ans.push_front(u);
not_used.erase(u);
}
return vec<int>(all(ans));
};
int T = 15;
vec<int> best;
while (T--) {
if (ct > border) break;
auto g = attempt();
if (len(g) > len(best))
best = g;
if (len(best) == n) break;
}
return best;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
7 ms |
344 KB |
Output is correct |
4 |
Correct |
8 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
344 KB |
Output is correct |
8 |
Correct |
6 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
484 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
15 ms |
344 KB |
Output is correct |
3 |
Correct |
38 ms |
344 KB |
Output is correct |
4 |
Correct |
62 ms |
344 KB |
Output is correct |
5 |
Correct |
63 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
38 ms |
420 KB |
Output is correct |
9 |
Correct |
42 ms |
344 KB |
Output is correct |
10 |
Correct |
76 ms |
600 KB |
Output is correct |
11 |
Correct |
64 ms |
600 KB |
Output is correct |
12 |
Correct |
61 ms |
492 KB |
Output is correct |
13 |
Correct |
68 ms |
596 KB |
Output is correct |
14 |
Correct |
107 ms |
344 KB |
Output is correct |
15 |
Correct |
123 ms |
344 KB |
Output is correct |
16 |
Correct |
20 ms |
344 KB |
Output is correct |
17 |
Correct |
44 ms |
344 KB |
Output is correct |
18 |
Correct |
33 ms |
344 KB |
Output is correct |
19 |
Correct |
40 ms |
344 KB |
Output is correct |
20 |
Correct |
46 ms |
344 KB |
Output is correct |
21 |
Correct |
66 ms |
344 KB |
Output is correct |
22 |
Correct |
69 ms |
344 KB |
Output is correct |
23 |
Correct |
71 ms |
344 KB |
Output is correct |
24 |
Correct |
71 ms |
348 KB |
Output is correct |
25 |
Correct |
145 ms |
344 KB |
Output is correct |
26 |
Correct |
126 ms |
344 KB |
Output is correct |
27 |
Correct |
292 ms |
344 KB |
Output is correct |
28 |
Correct |
297 ms |
344 KB |
Output is correct |
29 |
Correct |
322 ms |
344 KB |
Output is correct |
30 |
Correct |
695 ms |
344 KB |
Output is correct |
31 |
Correct |
483 ms |
344 KB |
Output is correct |
32 |
Correct |
413 ms |
344 KB |
Output is correct |
33 |
Correct |
694 ms |
600 KB |
Output is correct |
34 |
Correct |
684 ms |
344 KB |
Output is correct |
35 |
Correct |
654 ms |
600 KB |
Output is correct |
36 |
Correct |
345 ms |
492 KB |
Output is correct |
37 |
Correct |
342 ms |
600 KB |
Output is correct |
38 |
Incorrect |
353 ms |
848 KB |
too many elements |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
17 ms |
344 KB |
Output is correct |
3 |
Correct |
36 ms |
344 KB |
Output is correct |
4 |
Partially correct |
63 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
74 ms |
488 KB |
Output is partially correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
44 ms |
416 KB |
Output is correct |
9 |
Partially correct |
56 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
72 ms |
600 KB |
Output is partially correct |
11 |
Partially correct |
72 ms |
592 KB |
Output is partially correct |
12 |
Partially correct |
67 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
72 ms |
600 KB |
Output is partially correct |
14 |
Correct |
125 ms |
344 KB |
Output is correct |
15 |
Correct |
106 ms |
344 KB |
Output is correct |
16 |
Correct |
27 ms |
344 KB |
Output is correct |
17 |
Correct |
32 ms |
344 KB |
Output is correct |
18 |
Partially correct |
43 ms |
344 KB |
Output is partially correct |
19 |
Partially correct |
48 ms |
344 KB |
Output is partially correct |
20 |
Partially correct |
43 ms |
344 KB |
Output is partially correct |
21 |
Correct |
130 ms |
344 KB |
Output is correct |
22 |
Correct |
105 ms |
344 KB |
Output is correct |
23 |
Partially correct |
309 ms |
344 KB |
Output is partially correct |
24 |
Partially correct |
279 ms |
344 KB |
Output is partially correct |
25 |
Partially correct |
287 ms |
344 KB |
Output is partially correct |
26 |
Partially correct |
646 ms |
344 KB |
Output is partially correct |
27 |
Partially correct |
476 ms |
344 KB |
Output is partially correct |
28 |
Partially correct |
389 ms |
344 KB |
Output is partially correct |
29 |
Partially correct |
720 ms |
344 KB |
Output is partially correct |
30 |
Partially correct |
664 ms |
344 KB |
Output is partially correct |
31 |
Partially correct |
636 ms |
344 KB |
Output is partially correct |
32 |
Correct |
10 ms |
344 KB |
Output is correct |
33 |
Correct |
12 ms |
344 KB |
Output is correct |
34 |
Correct |
47 ms |
344 KB |
Output is correct |
35 |
Correct |
26 ms |
344 KB |
Output is correct |
36 |
Correct |
35 ms |
344 KB |
Output is correct |
37 |
Incorrect |
97 ms |
344 KB |
Incorrect |
38 |
Halted |
0 ms |
0 KB |
- |