#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector <int> longest_trip(int N, int D){
if (D>1){
deque <int> q={0};
if (!are_connected({0},{1}))
q.push_back(2);
q.push_back(1);
for (int i=q.size();i<N;i++)
if (are_connected({i},{q.front()}))
q.push_front(i);
else
q.push_back(i);
vector <int> res;
for (int i:q)
res.push_back(i);
return res;
}
vector <int> a,b;
a.push_back(0);
b.push_back(1);
for (int i=2;i<N;i++){
if (are_connected({a.back()},{i})){
a.push_back(i);
continue;
}
if (are_connected({b.back()},{i})){
b.push_back(i);
continue;
}
reverse(b.begin(),b.end());
for (int i:b)
a.push_back(i);
b={i};
}
if (a.size()<b.size())
swap(a,b);
if (a.size()==2){
for (int i=0;i<b.size();i++)
if (are_connected({a[0]},{b[i]})){
reverse(a.begin(),a.end());
a.push_back(b[i]);
if (i)
a.push_back(b[0]);
return a;
}
else if (are_connected({a[1]},{b[i]})){
a.push_back(b[i]);
if (i)
a.push_back(b[0]);
return a;
}
return a;
}
if (are_connected({a[0]},{b[0]}))
reverse(a.begin(),a.end());
for (int i:b)
a.push_back(i);
return a;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i=0;i<b.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
596 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 |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
8 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 |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 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 |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
608 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Incorrect |
0 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 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 |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
340 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 |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
436 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Incorrect |
0 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |