#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int>V, A, B;
rep(i, n) {
V.pb(i);
swap(V[i], V[rng()%(i+1)]);
}
A.pb(V[0]);
for(int i=1; i<n; ++i) {
if(A.size()<B.size()) swap(A, B);
if(B.size()==0) {
B.pb(V[i]);
continue;
}
vector<int>X, Y;
X.pb(V[i]);
if(rng()%2) {
Y.pb(A.back());
if(are_connected(X, Y)) A.pb(V[i]);
else {
Y[0]=B.back();
if(are_connected(X, Y)) B.pb(V[i]);
else {
while(B.size()>0) {
A.pb(B.back());
B.pop_back();
}
B.pb(V[i]);
}
}
} else {
Y.pb(B.back());
if(are_connected(X, Y)) B.pb(V[i]);
else {
Y[0]=A.back();
if(are_connected(X, Y)) A.pb(V[i]);
else {
while(B.size()>0) {
A.pb(B.back());
B.pop_back();
}
B.pb(V[i]);
}
}
}
if(rng()%2) reverse(all(A));
if(rng()%2) reverse(all(B));
}
if(A.size()>B.size()) swap(A, B);
if(A.size()==0) return B;
int po=0, ko=A.size();
while(po<ko) {
int sr=(po+ko)/2;
vector<int>tmp;
rep(i, sr+1) tmp.pb(A[i]);
if(are_connected(tmp, B)) ko=sr; else po=sr+1;
}
if(ko==A.size()) return A;
vector<int>X={A[po]};
int po2=0, ko2=B.size()-1;
while(po2<ko2) {
int sr=(po2+ko2)/2;
vector<int>tmp, xdx;
rep(i, sr+1) tmp.pb(B[i]);
if(are_connected(X, tmp)) ko2=sr; else po2=sr+1;
}
vector<int>ans;
rep(i, A.size()) ans.pb(A[(i+po+1)%A.size()]);
rep(i, B.size()) ans.pb(B[(i+po2)%B.size()]);
return ans;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:66:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | if(ko==A.size()) return A;
| ~~^~~~~~~~~~
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
longesttrip.cpp:76:3: note: in expansion of macro 'rep'
76 | rep(i, A.size()) ans.pb(A[(i+po+1)%A.size()]);
| ^~~
longesttrip.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
longesttrip.cpp:77:3: note: in expansion of macro 'rep'
77 | rep(i, B.size()) ans.pb(B[(i+po2)%B.size()]);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
208 KB |
Output is correct |
2 |
Correct |
13 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
208 KB |
Output is correct |
2 |
Correct |
14 ms |
208 KB |
Output is correct |
3 |
Correct |
11 ms |
304 KB |
Output is correct |
4 |
Correct |
11 ms |
208 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
18 ms |
208 KB |
Output is correct |
7 |
Incorrect |
2 ms |
208 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
208 KB |
Output is correct |
2 |
Correct |
14 ms |
208 KB |
Output is correct |
3 |
Correct |
10 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
208 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Incorrect |
1 ms |
208 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
208 KB |
Output is correct |
2 |
Correct |
14 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
15 ms |
208 KB |
Output is correct |
7 |
Incorrect |
2 ms |
208 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |