#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(vec, 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |