#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> longest_trip(int N, int D)
{
if(D>=2){
vector<int> ans;
vector<int> v1;
vector<int> v2;
if(N==3){
v1={0};
v2={1};
if(are_connected(v1,v2)){
v1={0};
v2={2};
if(are_connected(v1,v2)){
ans={1,0,2};
return ans;
}
else{
ans={0,1,2};
return ans;
}
}
else{
ans={0,2,1};
return ans;
}
}
ans.pb(0);
for(int i=1; i<N-1; ++i){
v1={ans[ans.size()-1]};
v2={i};
if(are_connected(v1, v2)){
ans.pb(i);
}
else{
i++;
ans.pb(i);
ans.pb(i-1);
}
}
if(ans.size()==N) return ans;
v1={ans[ans.size()-1]};
v2={N-1};
if(are_connected(v1, v2)){
ans.pb(N-1);
}
else{
int a=ans[ans.size()-1];
ans.pop_back();
int b=ans[ans.size()-1];
ans.pop_back();
ans.pb(N-1);
ans.pb(b);
ans.pb(a);
}
return ans;
}
stack<int> sk1;
stack<int> sk2;
sk1.push(0);
vector<int> v1;
vector<int> v2;
for(int i=1; i<N; ++i){
v1={sk1.top()};
v2={i};
if(are_connected(v1,v2)){
sk1.push(i);
}
else{
if(!sk2.empty()){
v1={sk2.top()};
if(are_connected(v1,v2)){
sk2.push(i);
}
else{
while(!sk2.empty()){
sk1.push(sk2.top());
sk2.pop();
}
sk2.push(i);
}
}
else{
sk2.push(i);
}
}
}
vector<int> ans1;
vector<int> ans2;
while(!sk1.empty()){
ans1.pb(sk1.top());
sk1.pop();
}
while(!sk2.empty()){
ans2.pb(sk2.top());
sk2.pop();
}
if(ans1.size()>ans2.size()) return ans1;
return ans2;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:44:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | if(ans.size()==N) return ans;
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
2 ms |
600 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
6 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
440 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
5 ms |
600 KB |
Output is correct |
11 |
Correct |
5 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
6 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
344 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 |
344 KB |
Output is correct |
16 |
Correct |
7 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 |
6 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
600 KB |
Output is correct |
21 |
Correct |
6 ms |
432 KB |
Output is correct |
22 |
Correct |
6 ms |
600 KB |
Output is correct |
23 |
Correct |
5 ms |
600 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
516 KB |
Output is correct |
26 |
Correct |
7 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 |
6 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
7 ms |
344 KB |
Output is correct |
32 |
Correct |
7 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 |
6 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
600 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
5 ms |
344 KB |
Output is correct |
39 |
Correct |
7 ms |
600 KB |
Output is correct |
40 |
Correct |
6 ms |
344 KB |
Output is correct |
41 |
Correct |
6 ms |
600 KB |
Output is correct |
42 |
Correct |
6 ms |
600 KB |
Output is correct |
43 |
Correct |
7 ms |
600 KB |
Output is correct |
44 |
Correct |
6 ms |
600 KB |
Output is correct |
45 |
Correct |
7 ms |
344 KB |
Output is correct |
46 |
Correct |
7 ms |
344 KB |
Output is correct |
47 |
Correct |
5 ms |
344 KB |
Output is correct |
48 |
Correct |
6 ms |
344 KB |
Output is correct |
49 |
Correct |
6 ms |
344 KB |
Output is correct |
50 |
Correct |
5 ms |
344 KB |
Output is correct |
51 |
Correct |
7 ms |
344 KB |
Output is correct |
52 |
Correct |
6 ms |
344 KB |
Output is correct |
53 |
Correct |
6 ms |
344 KB |
Output is correct |
54 |
Correct |
5 ms |
600 KB |
Output is correct |
55 |
Correct |
5 ms |
344 KB |
Output is correct |
56 |
Correct |
5 ms |
344 KB |
Output is correct |
57 |
Correct |
7 ms |
600 KB |
Output is correct |
58 |
Correct |
6 ms |
600 KB |
Output is correct |
59 |
Correct |
6 ms |
600 KB |
Output is correct |
60 |
Correct |
7 ms |
600 KB |
Output is correct |
61 |
Correct |
7 ms |
600 KB |
Output is correct |
62 |
Correct |
7 ms |
432 KB |
Output is correct |
63 |
Correct |
6 ms |
600 KB |
Output is correct |
64 |
Correct |
9 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
5 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 |
600 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |