#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
int i, j, k, a, b, A[260][260], B[260];
vector<int> longest_trip(int N, int D)
{
vector<int>v1, v2;
v1.push_back(0);
v2.push_back(1);
bool flag=false;
for(i=2;i<N;i++)
{
vector<int>X, Y, Z;
X.push_back(v1.back());Y.push_back(i);Z.push_back(v2.back());
if(are_connected(X, Y))v1.push_back(i);
else if(are_connected(Y, Z))v2.push_back(i);
else
{
while(v2.size())
{
v1.push_back(v2.back());
v2.pop_back();
}
v2.push_back(i);
}
}
if(are_connected(v1, v2)==0)
{
if(v1.size()<v2.size())swap(v1, v2);
return v1;
}
vector<int>X, Y, Z, W;
X.push_back(v1.back());
Z.push_back(v2[0]);W.push_back(v2.back());
if(are_connected(X, Z))
{
for(auto p:v2)v1.push_back(p);
return v1;
}
if(are_connected(X, W))
{
while(v2.size())
{
v1.push_back(v2.back());
v2.pop_back();
}
return v1;
}
if(are_connected(X, v2))
{
int s=0, e=v2.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(X, V))e=m;
else s=m+1;
}
for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
for(i=0;i<s;i++)v1.push_back(v2[i]);
return v1;
}
Y.push_back(v1[0]);
if(are_connected(Y, v2))
{
int s=0, e=v2.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(Y, V))e=m;
else s=m+1;
}
reverse(v1.begin(), v1.end());
for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
for(i=0;i<s;i++)v1.push_back(v2[i]);
return v1;
}
int s=0, e=v1.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v1[i]);
if(are_connected(V, v2))e=m;
else s=m+1;
}
int ss=s;
s=0, e=v2.size()-1;
X[0]=v1[ss];
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(X, V))e=m;
else s=m+1;
}
vector<int>ans;
for(i=ss-1;i>=0;i--)ans.push_back(v1[i]);
for(i=v1.size()-1;i>=ss;i--)ans.push_back(v1[i]);
for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
for(i=0;i<s;i++)ans.push_back(v2[i]);
v1=v2;
return ans;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:55:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int m=s+e>>1;
| ~^~
longesttrip.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:71:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int m=s+e>>1;
| ~^~
longesttrip.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:85:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int m=s+e>>1;
| ~^~
longesttrip.cpp:96:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int m=s+e>>1;
| ~^~
longesttrip.cpp:105:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:11:10: warning: unused variable 'flag' [-Wunused-variable]
11 | bool flag=false;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 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 |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
5 ms |
608 KB |
Output is correct |
11 |
Correct |
5 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
344 KB |
Output is correct |
13 |
Correct |
5 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 |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
5 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
600 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
596 KB |
Output is correct |
20 |
Correct |
5 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
600 KB |
Output is correct |
22 |
Correct |
5 ms |
852 KB |
Output is correct |
23 |
Correct |
7 ms |
448 KB |
Output is correct |
24 |
Correct |
5 ms |
600 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
7 ms |
344 KB |
Output is correct |
29 |
Correct |
6 ms |
344 KB |
Output is correct |
30 |
Correct |
4 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
7 ms |
344 KB |
Output is correct |
33 |
Correct |
6 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
5 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
5 ms |
344 KB |
Output is correct |
39 |
Correct |
6 ms |
600 KB |
Output is correct |
40 |
Correct |
8 ms |
344 KB |
Output is correct |
41 |
Correct |
7 ms |
344 KB |
Output is correct |
42 |
Correct |
7 ms |
344 KB |
Output is correct |
43 |
Correct |
8 ms |
340 KB |
Output is correct |
44 |
Correct |
7 ms |
600 KB |
Output is correct |
45 |
Correct |
13 ms |
344 KB |
Output is correct |
46 |
Correct |
10 ms |
344 KB |
Output is correct |
47 |
Correct |
8 ms |
344 KB |
Output is correct |
48 |
Correct |
8 ms |
344 KB |
Output is correct |
49 |
Correct |
9 ms |
344 KB |
Output is correct |
50 |
Correct |
6 ms |
444 KB |
Output is correct |
51 |
Correct |
8 ms |
600 KB |
Output is correct |
52 |
Correct |
7 ms |
344 KB |
Output is correct |
53 |
Correct |
5 ms |
344 KB |
Output is correct |
54 |
Correct |
5 ms |
344 KB |
Output is correct |
55 |
Correct |
6 ms |
344 KB |
Output is correct |
56 |
Correct |
5 ms |
604 KB |
Output is correct |
57 |
Correct |
6 ms |
452 KB |
Output is correct |
58 |
Correct |
7 ms |
604 KB |
Output is correct |
59 |
Correct |
8 ms |
700 KB |
Output is correct |
60 |
Correct |
10 ms |
704 KB |
Output is correct |
61 |
Correct |
8 ms |
444 KB |
Output is correct |
62 |
Correct |
8 ms |
444 KB |
Output is correct |
63 |
Correct |
7 ms |
608 KB |
Output is correct |
64 |
Correct |
7 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
600 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
440 KB |
Output is correct |
10 |
Correct |
5 ms |
600 KB |
Output is correct |
11 |
Correct |
5 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
440 KB |
Output is correct |
21 |
Correct |
6 ms |
344 KB |
Output is correct |
22 |
Correct |
7 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
344 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
4 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
344 KB |
Output is correct |
28 |
Correct |
6 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 |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Correct |
11 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
344 KB |
Output is correct |
35 |
Correct |
8 ms |
344 KB |
Output is correct |
36 |
Correct |
10 ms |
340 KB |
Output is correct |
37 |
Correct |
5 ms |
440 KB |
Output is correct |
38 |
Correct |
8 ms |
448 KB |
Output is correct |
39 |
Correct |
8 ms |
344 KB |
Output is correct |
40 |
Correct |
5 ms |
344 KB |
Output is correct |
41 |
Correct |
6 ms |
344 KB |
Output is correct |
42 |
Correct |
6 ms |
344 KB |
Output is correct |
43 |
Correct |
5 ms |
344 KB |
Output is correct |
44 |
Correct |
5 ms |
344 KB |
Output is correct |
45 |
Correct |
6 ms |
756 KB |
Output is correct |
46 |
Correct |
5 ms |
344 KB |
Output is correct |
47 |
Correct |
4 ms |
344 KB |
Output is correct |
48 |
Correct |
5 ms |
344 KB |
Output is correct |
49 |
Correct |
6 ms |
600 KB |
Output is correct |
50 |
Correct |
6 ms |
600 KB |
Output is correct |
51 |
Partially correct |
7 ms |
344 KB |
Output is partially correct |
52 |
Correct |
6 ms |
344 KB |
Output is correct |
53 |
Correct |
6 ms |
344 KB |
Output is correct |
54 |
Correct |
8 ms |
344 KB |
Output is correct |
55 |
Correct |
7 ms |
344 KB |
Output is correct |
56 |
Correct |
5 ms |
596 KB |
Output is correct |
57 |
Partially correct |
6 ms |
344 KB |
Output is partially correct |
58 |
Partially correct |
8 ms |
444 KB |
Output is partially correct |
59 |
Partially correct |
7 ms |
608 KB |
Output is partially correct |
60 |
Correct |
8 ms |
600 KB |
Output is correct |
61 |
Correct |
7 ms |
344 KB |
Output is correct |
62 |
Correct |
6 ms |
600 KB |
Output is correct |
63 |
Partially correct |
7 ms |
608 KB |
Output is partially correct |
64 |
Partially correct |
7 ms |
604 KB |
Output is partially correct |
65 |
Partially correct |
7 ms |
452 KB |
Output is partially correct |
66 |
Partially correct |
10 ms |
696 KB |
Output is partially correct |
67 |
Partially correct |
8 ms |
444 KB |
Output is partially correct |
68 |
Partially correct |
9 ms |
604 KB |
Output is partially correct |
69 |
Partially correct |
8 ms |
444 KB |
Output is partially correct |
70 |
Partially correct |
9 ms |
444 KB |
Output is partially correct |
71 |
Correct |
6 ms |
608 KB |
Output is correct |
72 |
Partially correct |
7 ms |
608 KB |
Output is partially correct |
73 |
Partially correct |
7 ms |
600 KB |
Output is partially correct |
74 |
Partially correct |
8 ms |
604 KB |
Output is partially correct |
75 |
Partially correct |
7 ms |
852 KB |
Output is partially correct |
76 |
Partially correct |
8 ms |
600 KB |
Output is partially correct |
77 |
Correct |
6 ms |
448 KB |
Output is correct |
78 |
Partially correct |
6 ms |
704 KB |
Output is partially correct |
79 |
Correct |
6 ms |
444 KB |
Output is correct |
80 |
Partially correct |
7 ms |
604 KB |
Output is partially correct |
81 |
Partially correct |
7 ms |
600 KB |
Output is partially correct |
82 |
Partially correct |
7 ms |
604 KB |
Output is partially correct |