#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
already knew the solution
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "longesttrip.h"
std::vector<int> longest_trip(int n, int d)
{
vector<deque<int>> paths;
rep(i,n){
paths.pb({i});
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int q = 0;
while(sz(paths) >= 3){
int siz = sz(paths);
vector<int> ord(siz);
rep(i,siz) ord[i] = i;
shuffle(all(ord),rng);
auto p1 = paths[ord[0]];
auto p2 = paths[ord[1]];
auto p3 = paths[ord[2]];
vector<deque<int>> new_paths;
rep(i,siz){
bool ok = true;
rep(j,3){
if(i == ord[j]){
ok = false;
}
}
if(ok){
new_paths.pb(paths[i]);
}
}
int u = p1[0], v = p2[0], w = p3[0];
if(are_connected({u},{v})){
q++;
while(!p2.empty()){
p1.push_front(p2.front());
p2.pop_front();
}
}
else if(are_connected({u},{w})){
q += 2;
while(!p3.empty()){
p1.push_front(p3.front());
p3.pop_front();
}
}
else{
q += 2;
while(!p3.empty()){
p2.push_front(p3.front());
p3.pop_front();
}
}
if(!p1.empty()){
new_paths.pb(p1);
}
if(!p2.empty()){
new_paths.pb(p2);
}
if(!p3.empty()){
new_paths.pb(p3);
}
paths = new_paths;
}
auto p1 = paths[0], p2 = paths[1];
if(are_connected({p1[0]},{p2[0]})){
q++;
while(!p2.empty()){
p1.push_front(p2.front());
p2.pop_front();
}
}
else if(are_connected({p1[0]},{p2.back()})){
q += 2;
while(!p2.empty()){
p1.push_front(p2.back());
p2.pop_back();
}
}
else if(are_connected({p1.back()},{p2[0]})){
q += 3;
while(!p2.empty()){
p1.pb(p2.front());
p2.pop_front();
}
}
else if(are_connected({p1.back()},{p2.back()})){
q += 4;
while(!p2.empty()){
p1.pb(p2.back());
p2.pop_back();
}
}
if(p2.empty()){
return vector<int>(all(p1));
}
int l = 0, r = sz(p1)-1;
int pos1 = -1;
while(l <= r){
int mid = (l+r) >> 1;
vector<int> v1;
rep(i,mid+1){
v1.pb(p1[i]);
}
vector<int> v2(all(p2));
q++;
if(are_connected(v1,v2)){
pos1 = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
if(pos1 == -1){
if(sz(p1) > sz(p2)){
return vector<int>(all(p1));
}
else{
return vector<int>(all(p2));
}
}
l = 0, r = sz(p2)-1;
int pos2 = -1;
while(l <= r){
int mid = (l+r) >> 1;
vector<int> v1 = {p1[pos1]};
vector<int> v2;
rep(i,mid+1){
v2.pb(p2[i]);
}
q++;
if(are_connected(v1,v2)){
pos2 = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
assert(pos2 != -1);
assert(q <= 410);
rotate(p1.begin(),p1.begin()+pos1,p1.end());
rotate(p2.begin(),p2.begin()+pos2,p2.end());
while(!p2.empty()){
p1.push_front(p2.front());
p2.pop_front();
}
return vector<int>(all(p1));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
600 KB |
Output is correct |
4 |
Correct |
16 ms |
856 KB |
Output is correct |
5 |
Correct |
25 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
856 KB |
Output is correct |
4 |
Correct |
17 ms |
1368 KB |
Output is correct |
5 |
Correct |
24 ms |
788 KB |
Output is correct |
6 |
Correct |
10 ms |
368 KB |
Output is correct |
7 |
Correct |
8 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
600 KB |
Output is correct |
9 |
Correct |
15 ms |
600 KB |
Output is correct |
10 |
Correct |
25 ms |
856 KB |
Output is correct |
11 |
Correct |
25 ms |
856 KB |
Output is correct |
12 |
Correct |
25 ms |
856 KB |
Output is correct |
13 |
Correct |
25 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
612 KB |
Output is correct |
4 |
Correct |
15 ms |
856 KB |
Output is correct |
5 |
Correct |
25 ms |
948 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
516 KB |
Output is correct |
9 |
Correct |
15 ms |
344 KB |
Output is correct |
10 |
Correct |
32 ms |
788 KB |
Output is correct |
11 |
Correct |
24 ms |
856 KB |
Output is correct |
12 |
Correct |
27 ms |
856 KB |
Output is correct |
13 |
Correct |
29 ms |
856 KB |
Output is correct |
14 |
Correct |
17 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
9 ms |
344 KB |
Output is correct |
17 |
Correct |
9 ms |
600 KB |
Output is correct |
18 |
Correct |
11 ms |
512 KB |
Output is correct |
19 |
Correct |
14 ms |
856 KB |
Output is correct |
20 |
Correct |
15 ms |
600 KB |
Output is correct |
21 |
Correct |
25 ms |
856 KB |
Output is correct |
22 |
Correct |
27 ms |
856 KB |
Output is correct |
23 |
Correct |
28 ms |
856 KB |
Output is correct |
24 |
Correct |
26 ms |
856 KB |
Output is correct |
25 |
Correct |
13 ms |
344 KB |
Output is correct |
26 |
Correct |
14 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
12 ms |
600 KB |
Output is correct |
29 |
Correct |
13 ms |
344 KB |
Output is correct |
30 |
Correct |
14 ms |
532 KB |
Output is correct |
31 |
Correct |
17 ms |
524 KB |
Output is correct |
32 |
Correct |
14 ms |
784 KB |
Output is correct |
33 |
Correct |
15 ms |
600 KB |
Output is correct |
34 |
Correct |
15 ms |
344 KB |
Output is correct |
35 |
Correct |
15 ms |
600 KB |
Output is correct |
36 |
Correct |
25 ms |
788 KB |
Output is correct |
37 |
Correct |
26 ms |
784 KB |
Output is correct |
38 |
Correct |
28 ms |
856 KB |
Output is correct |
39 |
Correct |
27 ms |
600 KB |
Output is correct |
40 |
Correct |
27 ms |
788 KB |
Output is correct |
41 |
Correct |
27 ms |
856 KB |
Output is correct |
42 |
Correct |
28 ms |
856 KB |
Output is correct |
43 |
Correct |
33 ms |
800 KB |
Output is correct |
44 |
Correct |
29 ms |
1036 KB |
Output is correct |
45 |
Correct |
11 ms |
344 KB |
Output is correct |
46 |
Correct |
10 ms |
344 KB |
Output is correct |
47 |
Correct |
9 ms |
344 KB |
Output is correct |
48 |
Correct |
9 ms |
344 KB |
Output is correct |
49 |
Correct |
9 ms |
600 KB |
Output is correct |
50 |
Correct |
12 ms |
784 KB |
Output is correct |
51 |
Correct |
14 ms |
780 KB |
Output is correct |
52 |
Correct |
14 ms |
528 KB |
Output is correct |
53 |
Correct |
15 ms |
612 KB |
Output is correct |
54 |
Correct |
15 ms |
344 KB |
Output is correct |
55 |
Correct |
18 ms |
592 KB |
Output is correct |
56 |
Correct |
32 ms |
856 KB |
Output is correct |
57 |
Correct |
29 ms |
856 KB |
Output is correct |
58 |
Correct |
29 ms |
788 KB |
Output is correct |
59 |
Correct |
28 ms |
856 KB |
Output is correct |
60 |
Correct |
30 ms |
856 KB |
Output is correct |
61 |
Correct |
27 ms |
856 KB |
Output is correct |
62 |
Correct |
29 ms |
800 KB |
Output is correct |
63 |
Correct |
28 ms |
792 KB |
Output is correct |
64 |
Runtime error |
15 ms |
1344 KB |
Execution killed with signal 6 |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
18 ms |
868 KB |
Output is correct |
5 |
Correct |
26 ms |
780 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
600 KB |
Output is correct |
9 |
Correct |
13 ms |
344 KB |
Output is correct |
10 |
Correct |
24 ms |
856 KB |
Output is correct |
11 |
Correct |
25 ms |
856 KB |
Output is correct |
12 |
Correct |
25 ms |
856 KB |
Output is correct |
13 |
Correct |
27 ms |
856 KB |
Output is correct |
14 |
Correct |
18 ms |
344 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
10 ms |
600 KB |
Output is correct |
17 |
Correct |
9 ms |
344 KB |
Output is correct |
18 |
Correct |
11 ms |
600 KB |
Output is correct |
19 |
Correct |
14 ms |
600 KB |
Output is correct |
20 |
Correct |
15 ms |
592 KB |
Output is correct |
21 |
Correct |
15 ms |
344 KB |
Output is correct |
22 |
Correct |
14 ms |
344 KB |
Output is correct |
23 |
Correct |
10 ms |
344 KB |
Output is correct |
24 |
Correct |
10 ms |
344 KB |
Output is correct |
25 |
Correct |
11 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
524 KB |
Output is correct |
27 |
Correct |
15 ms |
796 KB |
Output is correct |
28 |
Correct |
18 ms |
532 KB |
Output is correct |
29 |
Correct |
18 ms |
600 KB |
Output is correct |
30 |
Correct |
18 ms |
344 KB |
Output is correct |
31 |
Correct |
15 ms |
592 KB |
Output is correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Correct |
9 ms |
344 KB |
Output is correct |
34 |
Correct |
10 ms |
344 KB |
Output is correct |
35 |
Correct |
11 ms |
600 KB |
Output is correct |
36 |
Correct |
10 ms |
344 KB |
Output is correct |
37 |
Correct |
12 ms |
528 KB |
Output is correct |
38 |
Correct |
14 ms |
528 KB |
Output is correct |
39 |
Correct |
15 ms |
784 KB |
Output is correct |
40 |
Correct |
15 ms |
856 KB |
Output is correct |
41 |
Correct |
15 ms |
588 KB |
Output is correct |
42 |
Correct |
15 ms |
344 KB |
Output is correct |
43 |
Correct |
28 ms |
856 KB |
Output is correct |
44 |
Correct |
29 ms |
856 KB |
Output is correct |
45 |
Correct |
25 ms |
788 KB |
Output is correct |
46 |
Correct |
26 ms |
784 KB |
Output is correct |
47 |
Correct |
25 ms |
856 KB |
Output is correct |
48 |
Correct |
27 ms |
796 KB |
Output is correct |
49 |
Correct |
27 ms |
856 KB |
Output is correct |
50 |
Correct |
27 ms |
796 KB |
Output is correct |
51 |
Correct |
28 ms |
788 KB |
Output is correct |
52 |
Partially correct |
28 ms |
780 KB |
Output is partially correct |
53 |
Correct |
28 ms |
856 KB |
Output is correct |
54 |
Correct |
28 ms |
856 KB |
Output is correct |
55 |
Partially correct |
31 ms |
856 KB |
Output is partially correct |
56 |
Correct |
26 ms |
788 KB |
Output is correct |
57 |
Correct |
27 ms |
784 KB |
Output is correct |
58 |
Correct |
27 ms |
856 KB |
Output is correct |
59 |
Correct |
27 ms |
856 KB |
Output is correct |
60 |
Partially correct |
27 ms |
852 KB |
Output is partially correct |
61 |
Correct |
28 ms |
856 KB |
Output is correct |
62 |
Correct |
29 ms |
828 KB |
Output is correct |
63 |
Correct |
26 ms |
784 KB |
Output is correct |
64 |
Correct |
29 ms |
856 KB |
Output is correct |
65 |
Partially correct |
29 ms |
856 KB |
Output is partially correct |
66 |
Partially correct |
31 ms |
856 KB |
Output is partially correct |
67 |
Partially correct |
28 ms |
784 KB |
Output is partially correct |
68 |
Partially correct |
28 ms |
784 KB |
Output is partially correct |
69 |
Partially correct |
28 ms |
784 KB |
Output is partially correct |
70 |
Partially correct |
30 ms |
856 KB |
Output is partially correct |
71 |
Correct |
27 ms |
788 KB |
Output is correct |
72 |
Correct |
29 ms |
1108 KB |
Output is correct |
73 |
Correct |
27 ms |
884 KB |
Output is correct |
74 |
Correct |
28 ms |
856 KB |
Output is correct |
75 |
Runtime error |
8 ms |
1296 KB |
Execution killed with signal 6 |
76 |
Halted |
0 ms |
0 KB |
- |