#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 * 1200;
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 |
14 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
7 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
344 KB |
Output is correct |
13 |
Correct |
7 ms |
344 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 |
31 ms |
344 KB |
Output is correct |
4 |
Correct |
50 ms |
456 KB |
Output is correct |
5 |
Correct |
66 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
29 ms |
344 KB |
Output is correct |
9 |
Correct |
45 ms |
344 KB |
Output is correct |
10 |
Correct |
65 ms |
600 KB |
Output is correct |
11 |
Correct |
61 ms |
344 KB |
Output is correct |
12 |
Correct |
81 ms |
344 KB |
Output is correct |
13 |
Correct |
59 ms |
344 KB |
Output is correct |
14 |
Correct |
114 ms |
344 KB |
Output is correct |
15 |
Correct |
125 ms |
344 KB |
Output is correct |
16 |
Correct |
21 ms |
344 KB |
Output is correct |
17 |
Correct |
32 ms |
344 KB |
Output is correct |
18 |
Correct |
31 ms |
344 KB |
Output is correct |
19 |
Correct |
49 ms |
344 KB |
Output is correct |
20 |
Correct |
43 ms |
344 KB |
Output is correct |
21 |
Correct |
65 ms |
600 KB |
Output is correct |
22 |
Correct |
71 ms |
520 KB |
Output is correct |
23 |
Correct |
69 ms |
344 KB |
Output is correct |
24 |
Correct |
93 ms |
720 KB |
Output is correct |
25 |
Correct |
164 ms |
344 KB |
Output is correct |
26 |
Correct |
124 ms |
344 KB |
Output is correct |
27 |
Correct |
274 ms |
344 KB |
Output is correct |
28 |
Correct |
265 ms |
344 KB |
Output is correct |
29 |
Correct |
307 ms |
596 KB |
Output is correct |
30 |
Correct |
648 ms |
344 KB |
Output is correct |
31 |
Correct |
475 ms |
344 KB |
Output is correct |
32 |
Correct |
411 ms |
344 KB |
Output is correct |
33 |
Correct |
613 ms |
604 KB |
Output is correct |
34 |
Correct |
614 ms |
344 KB |
Output is correct |
35 |
Correct |
592 ms |
448 KB |
Output is correct |
36 |
Correct |
336 ms |
748 KB |
Output is correct |
37 |
Correct |
350 ms |
480 KB |
Output is correct |
38 |
Correct |
296 ms |
344 KB |
Output is correct |
39 |
Correct |
260 ms |
600 KB |
Output is correct |
40 |
Correct |
246 ms |
344 KB |
Output is correct |
41 |
Correct |
265 ms |
344 KB |
Output is correct |
42 |
Correct |
252 ms |
344 KB |
Output is correct |
43 |
Correct |
250 ms |
344 KB |
Output is correct |
44 |
Correct |
253 ms |
344 KB |
Output is correct |
45 |
Correct |
14 ms |
344 KB |
Output is correct |
46 |
Correct |
10 ms |
344 KB |
Output is correct |
47 |
Correct |
42 ms |
344 KB |
Output is correct |
48 |
Correct |
36 ms |
344 KB |
Output is correct |
49 |
Correct |
36 ms |
344 KB |
Output is correct |
50 |
Correct |
342 ms |
344 KB |
Output is correct |
51 |
Correct |
234 ms |
344 KB |
Output is correct |
52 |
Correct |
167 ms |
348 KB |
Output is correct |
53 |
Correct |
486 ms |
344 KB |
Output is correct |
54 |
Correct |
401 ms |
596 KB |
Output is correct |
55 |
Correct |
535 ms |
600 KB |
Output is correct |
56 |
Correct |
256 ms |
724 KB |
Output is correct |
57 |
Correct |
362 ms |
344 KB |
Output is correct |
58 |
Correct |
256 ms |
344 KB |
Output is correct |
59 |
Correct |
116 ms |
716 KB |
Output is correct |
60 |
Correct |
309 ms |
600 KB |
Output is correct |
61 |
Correct |
243 ms |
488 KB |
Output is correct |
62 |
Correct |
204 ms |
476 KB |
Output is correct |
63 |
Correct |
287 ms |
480 KB |
Output is correct |
64 |
Correct |
161 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
340 KB |
Output is correct |
3 |
Correct |
39 ms |
344 KB |
Output is correct |
4 |
Partially correct |
49 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
69 ms |
968 KB |
Output is partially correct |
6 |
Correct |
12 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
344 KB |
Output is correct |
8 |
Correct |
35 ms |
344 KB |
Output is correct |
9 |
Partially correct |
57 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
72 ms |
752 KB |
Output is partially correct |
11 |
Partially correct |
74 ms |
600 KB |
Output is partially correct |
12 |
Partially correct |
63 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
81 ms |
600 KB |
Output is partially correct |
14 |
Correct |
108 ms |
344 KB |
Output is correct |
15 |
Correct |
104 ms |
344 KB |
Output is correct |
16 |
Correct |
23 ms |
344 KB |
Output is correct |
17 |
Correct |
29 ms |
344 KB |
Output is correct |
18 |
Partially correct |
38 ms |
344 KB |
Output is partially correct |
19 |
Partially correct |
64 ms |
448 KB |
Output is partially correct |
20 |
Partially correct |
71 ms |
344 KB |
Output is partially correct |
21 |
Correct |
137 ms |
344 KB |
Output is correct |
22 |
Correct |
126 ms |
344 KB |
Output is correct |
23 |
Partially correct |
302 ms |
344 KB |
Output is partially correct |
24 |
Partially correct |
287 ms |
340 KB |
Output is partially correct |
25 |
Partially correct |
304 ms |
344 KB |
Output is partially correct |
26 |
Partially correct |
672 ms |
344 KB |
Output is partially correct |
27 |
Partially correct |
438 ms |
344 KB |
Output is partially correct |
28 |
Partially correct |
385 ms |
344 KB |
Output is partially correct |
29 |
Partially correct |
619 ms |
344 KB |
Output is partially correct |
30 |
Partially correct |
582 ms |
340 KB |
Output is partially correct |
31 |
Partially correct |
582 ms |
344 KB |
Output is partially correct |
32 |
Correct |
16 ms |
344 KB |
Output is correct |
33 |
Correct |
9 ms |
344 KB |
Output is correct |
34 |
Correct |
37 ms |
344 KB |
Output is correct |
35 |
Correct |
40 ms |
344 KB |
Output is correct |
36 |
Correct |
48 ms |
344 KB |
Output is correct |
37 |
Incorrect |
33 ms |
344 KB |
Incorrect |
38 |
Halted |
0 ms |
0 KB |
- |