#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
void nadi(vi &a, vi b){
int lo = 0, hi = (int)a.size() - 1, ret = -1;
while(lo <= hi){
int mid = (lo + hi) / 2;
vi vec;
for(int i=0; i<=mid; i++) vec.PB(i);
if(are_connected(a, b)) ret = mid, hi = mid - 1;
else lo = mid + 1;
}
int vl = a[ret];
while(a.back() != vl){
int x = a.back();
a.PPB();
reverse(all(a));
a.PB(x);
reverse(all(a));
}
}
vi longest_trip(int n, int d){
vi a = {0}, b = {1};
bool nula = 0;
for(int i=2; i<n; i++){
if(are_connected({a.back()}, {i})){
a.PB(i);
nula = 0;
continue;
}
if(nula or are_connected({b.back()}, {i})){
b.PB(i);
nula = 1;
continue;
}
while(b.size()) a.PB(b.back()), b.PPB();
b.PB(i);
}
if(a.size() < b.size()) swap(a, b);
if(!are_connected(a, b)) return a;
nadi(b, a);
nadi(a, {b.back()});
while(b.size()) a.PB(b.back()), b.PPB();
return a;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
7 ms |
344 KB |
Output is correct |
5 |
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 |
7 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 |
344 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
9 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 |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 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 |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |