#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(0);
std::vector<int> longest_trip(int N, int D)
{
vector<int>x,y;
x.push_back(0);
for(int i=1;i<N;i++){
if(are_connected({0}, {i})){
x.push_back(i);
} else{
y.push_back(i);
}
}
if(y.size()>0 && !are_connected(x,y)){
if(x.size()>y.size()){
return x;
} else{
return y;
}
}
if(y.size()>0){
vector<int>y_;
for(int i=0;i<N;i++){
if(find(y.begin(),y.end(),i)==y.end()){
y_.push_back(i);
}
}
int lo=0;
int hi=y.size()-1;
while(lo<hi){
int m=(lo+hi)/2;
vector<int>vv;
for(int i=lo;i<=m;i++){
vv.push_back(y[i]);
}
if(are_connected(vv, y_)){
hi=m;
} else{
lo=m+1;
}
}
swap(y[y.size()-1], y[lo]);
}
vector<int>ans = y;
vector<int>p;
if(y.size()==0){
ans.push_back({1});
}
for(int i=1;i<N;i++){
if(find(ans.begin(),ans.end(),i)==ans.end()){
p.push_back(i);
}
}
while(!p.empty()){
shuffle(p.begin(),p.end(),rng);
if(!are_connected({ans.back()}, p)){
break;
}
for(int i: p){
if(are_connected({ans.back()}, {i})){
ans.push_back(i);
p.erase(find(p.begin(),p.end(), i));
break;
}
}
}
ans.push_back(0);
for(int i: p){
ans.push_back(i);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
880 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 |
17 ms |
344 KB |
Output is correct |
4 |
Correct |
20 ms |
448 KB |
Output is correct |
5 |
Correct |
25 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
344 KB |
Output is correct |
4 |
Correct |
18 ms |
608 KB |
Output is correct |
5 |
Correct |
23 ms |
1136 KB |
Output is correct |
6 |
Correct |
12 ms |
344 KB |
Output is correct |
7 |
Correct |
15 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
17 ms |
604 KB |
Output is correct |
10 |
Correct |
26 ms |
976 KB |
Output is correct |
11 |
Correct |
28 ms |
472 KB |
Output is correct |
12 |
Correct |
25 ms |
468 KB |
Output is correct |
13 |
Correct |
29 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
17 ms |
600 KB |
Output is correct |
4 |
Correct |
18 ms |
860 KB |
Output is correct |
5 |
Correct |
23 ms |
468 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
17 ms |
444 KB |
Output is correct |
10 |
Correct |
25 ms |
704 KB |
Output is correct |
11 |
Correct |
26 ms |
632 KB |
Output is correct |
12 |
Correct |
26 ms |
476 KB |
Output is correct |
13 |
Correct |
23 ms |
1232 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
8 ms |
344 KB |
Output is correct |
16 |
Correct |
14 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
344 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
14 ms |
600 KB |
Output is correct |
20 |
Correct |
15 ms |
444 KB |
Output is correct |
21 |
Correct |
23 ms |
876 KB |
Output is correct |
22 |
Correct |
21 ms |
708 KB |
Output is correct |
23 |
Correct |
20 ms |
976 KB |
Output is correct |
24 |
Correct |
22 ms |
472 KB |
Output is correct |
25 |
Correct |
6 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
35 |
Correct |
5 ms |
344 KB |
Output is correct |
36 |
Correct |
4 ms |
600 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
4 ms |
600 KB |
Output is correct |
39 |
Correct |
5 ms |
344 KB |
Output is correct |
40 |
Correct |
4 ms |
344 KB |
Output is correct |
41 |
Correct |
4 ms |
344 KB |
Output is correct |
42 |
Correct |
5 ms |
600 KB |
Output is correct |
43 |
Correct |
4 ms |
344 KB |
Output is correct |
44 |
Correct |
6 ms |
344 KB |
Output is correct |
45 |
Correct |
11 ms |
344 KB |
Output is correct |
46 |
Correct |
12 ms |
344 KB |
Output is correct |
47 |
Correct |
13 ms |
344 KB |
Output is correct |
48 |
Correct |
12 ms |
344 KB |
Output is correct |
49 |
Correct |
12 ms |
344 KB |
Output is correct |
50 |
Correct |
16 ms |
436 KB |
Output is correct |
51 |
Correct |
11 ms |
444 KB |
Output is correct |
52 |
Correct |
12 ms |
344 KB |
Output is correct |
53 |
Correct |
17 ms |
444 KB |
Output is correct |
54 |
Correct |
21 ms |
600 KB |
Output is correct |
55 |
Correct |
18 ms |
444 KB |
Output is correct |
56 |
Correct |
27 ms |
724 KB |
Output is correct |
57 |
Correct |
20 ms |
884 KB |
Output is correct |
58 |
Correct |
13 ms |
712 KB |
Output is correct |
59 |
Correct |
14 ms |
700 KB |
Output is correct |
60 |
Correct |
14 ms |
700 KB |
Output is correct |
61 |
Correct |
15 ms |
852 KB |
Output is correct |
62 |
Correct |
14 ms |
448 KB |
Output is correct |
63 |
Correct |
11 ms |
704 KB |
Output is correct |
64 |
Correct |
13 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
756 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
14 ms |
600 KB |
Output is correct |
4 |
Correct |
20 ms |
860 KB |
Output is correct |
5 |
Partially correct |
25 ms |
1224 KB |
Output is partially correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
344 KB |
Output is correct |
8 |
Correct |
17 ms |
600 KB |
Output is correct |
9 |
Correct |
17 ms |
604 KB |
Output is correct |
10 |
Partially correct |
23 ms |
724 KB |
Output is partially correct |
11 |
Partially correct |
28 ms |
868 KB |
Output is partially correct |
12 |
Partially correct |
27 ms |
720 KB |
Output is partially correct |
13 |
Partially correct |
23 ms |
976 KB |
Output is partially correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
12 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
600 KB |
Output is correct |
18 |
Correct |
13 ms |
600 KB |
Output is correct |
19 |
Correct |
17 ms |
604 KB |
Output is correct |
20 |
Correct |
15 ms |
444 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
7 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
5 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
5 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
4 ms |
344 KB |
Output is correct |
32 |
Correct |
14 ms |
344 KB |
Output is correct |
33 |
Correct |
11 ms |
344 KB |
Output is correct |
34 |
Correct |
16 ms |
344 KB |
Output is correct |
35 |
Correct |
14 ms |
344 KB |
Output is correct |
36 |
Correct |
17 ms |
344 KB |
Output is correct |
37 |
Correct |
17 ms |
436 KB |
Output is correct |
38 |
Correct |
12 ms |
440 KB |
Output is correct |
39 |
Correct |
11 ms |
540 KB |
Output is correct |
40 |
Correct |
21 ms |
440 KB |
Output is correct |
41 |
Correct |
17 ms |
440 KB |
Output is correct |
42 |
Correct |
17 ms |
440 KB |
Output is correct |
43 |
Partially correct |
26 ms |
716 KB |
Output is partially correct |
44 |
Partially correct |
21 ms |
964 KB |
Output is partially correct |
45 |
Partially correct |
20 ms |
468 KB |
Output is partially correct |
46 |
Partially correct |
21 ms |
724 KB |
Output is partially correct |
47 |
Correct |
4 ms |
344 KB |
Output is correct |
48 |
Correct |
5 ms |
344 KB |
Output is correct |
49 |
Correct |
5 ms |
504 KB |
Output is correct |
50 |
Correct |
4 ms |
852 KB |
Output is correct |
51 |
Correct |
4 ms |
344 KB |
Output is correct |
52 |
Correct |
5 ms |
344 KB |
Output is correct |
53 |
Correct |
4 ms |
344 KB |
Output is correct |
54 |
Correct |
5 ms |
344 KB |
Output is correct |
55 |
Correct |
5 ms |
600 KB |
Output is correct |
56 |
Correct |
5 ms |
600 KB |
Output is correct |
57 |
Correct |
6 ms |
344 KB |
Output is correct |
58 |
Correct |
5 ms |
344 KB |
Output is correct |
59 |
Correct |
5 ms |
344 KB |
Output is correct |
60 |
Correct |
4 ms |
344 KB |
Output is correct |
61 |
Correct |
4 ms |
344 KB |
Output is correct |
62 |
Partially correct |
27 ms |
612 KB |
Output is partially correct |
63 |
Partially correct |
20 ms |
720 KB |
Output is partially correct |
64 |
Partially correct |
14 ms |
968 KB |
Output is partially correct |
65 |
Partially correct |
17 ms |
612 KB |
Output is partially correct |
66 |
Partially correct |
14 ms |
704 KB |
Output is partially correct |
67 |
Partially correct |
13 ms |
444 KB |
Output is partially correct |
68 |
Partially correct |
13 ms |
856 KB |
Output is partially correct |
69 |
Partially correct |
11 ms |
608 KB |
Output is partially correct |
70 |
Partially correct |
14 ms |
696 KB |
Output is partially correct |
71 |
Partially correct |
27 ms |
724 KB |
Output is partially correct |
72 |
Partially correct |
19 ms |
472 KB |
Output is partially correct |
73 |
Partially correct |
10 ms |
956 KB |
Output is partially correct |
74 |
Partially correct |
14 ms |
608 KB |
Output is partially correct |
75 |
Partially correct |
12 ms |
448 KB |
Output is partially correct |
76 |
Partially correct |
13 ms |
608 KB |
Output is partially correct |
77 |
Partially correct |
26 ms |
976 KB |
Output is partially correct |
78 |
Partially correct |
19 ms |
716 KB |
Output is partially correct |
79 |
Partially correct |
19 ms |
1112 KB |
Output is partially correct |
80 |
Partially correct |
13 ms |
956 KB |
Output is partially correct |
81 |
Partially correct |
13 ms |
448 KB |
Output is partially correct |
82 |
Partially correct |
14 ms |
700 KB |
Output is partially correct |