#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = (int)1e6 + 10;
int n;
ll X[N];
vector<ll> W;
ll L;
vector<pii> A,B;
pii Q[4][2];
void upd(int id, int mode, pii V){
if(mode == false){ // max
if(Q[id][0] < V){
Q[id][1] = Q[id][0];
Q[id][0] = V;
}
else if(Q[id][1] < V){
Q[id][1] = V;
}
}
else{
if(Q[id][0] > V){
Q[id][1] = Q[id][0];
Q[id][0] = V;
}
else{
Q[id][1] = V;
}
}
}
bool check(ll k){
ll mx = 0;
for(int i = 0 ; i < n; i ++ ){
if(W[i] + mx > k) return false;
mx = max(mx, W[i]);
}
ll lowplus = -(ll)1e18;
ll highplus = (ll)1e18;
ll lowminus = -(ll)1e18;
ll highminus = (ll)1e18;
/*
for(int i = 0 ; i < n; i ++ ){
for(int j = 0; j < n; j ++ ){
if(i == j) continue;
if(X[j] + W[j] - (X[i] - W[i]) <= k) continue; // no one cares
lowplus = max(lowplus, -k + X[i] + X[j] + L + W[i] + W[j]);
highplus = min(highplus, k + X[i] + X[j] - L - W[i] - W[j]);
lowminus = max(lowminus, -k + X[i] - X[j] + L + W[i] + W[j]);
highminus = min(highminus, k + X[i] - X[j] - L - W[i] - W[j]);
}
}
*/
Q[0][0] = Q[0][1] = mp(-(ll)1e18, -1);
Q[1][0] = Q[1][1] = mp((ll)1e18, -1);
Q[2][0] = Q[2][1] = mp(-(ll)1e18, -1);
Q[3][0] = Q[3][1] = mp((ll)1e18, -1);
int pi = 0;
int j;
ll extra;
for(int i = 0 ; i < n; i ++ ){
while(pi < n && A[i].fi - B[pi].fi > k){
upd(0, false, mp(X[B[pi].se] + W[B[pi].se], B[pi].se));
upd(1, true, mp(X[B[pi].se] - W[B[pi].se], B[pi].se));
upd(2, false, mp(X[B[pi].se] + W[B[pi].se], B[pi].se));
upd(3, true, mp(X[B[pi].se] - W[B[pi].se], B[pi].se));
pi ++ ;
}
j = A[i].se;
if(j == Q[0][0].se) extra = Q[0][1].fi;
else extra = Q[0][0].fi;
lowplus = max(lowplus, -k + X[j] + L + W[j] + extra);
if(j == Q[1][0].se) extra = Q[1][1].fi;
else extra = Q[1][0].fi;
highplus = min(highplus, k + X[j] - L - W[j] + extra);
if(j == Q[2][0].se) extra = Q[2][1].fi;
else extra = Q[2][0].fi;
lowminus = max(lowminus, -k - X[j] + L + W[j] + extra);
if(j == Q[3][0].se) extra = Q[3][1].fi;
else extra = Q[3][0].fi;
highminus = min(highminus, k - X[j] - L - W[j] + extra);
}
int i0 = n - 1, j0 = n - 1;
int i1 = 0, j1 = 0;
int tl, tr;
for(int i = 0 ; i < n; i ++ ){
while(i0 >= 0 && X[i] + X[i0] > highplus){
i0 -- ;
}
while(j0 > 0 && X[i] + X[j0 - 1] >= lowplus){
j0 -- ;
}
while(i1 < n && X[i] - X[i1] > highminus){
i1 ++ ;
}
while(j1 + 1 < n && X[i] - X[j1 + 1] >= lowminus){
j1 ++ ;
}
tl = i + 1;
tr = n - 1;
tl = max(tl, j0);
tr = min(tr, i0);
tl = max(tl, i1);
tr = min(tr, j1);
if(tl <= tr){
return true;
}
}
return false;
}
ll find_shortcut(int _n, vector<int> l, vector<int> _d, int _c){
n = _n;
for(int i = 1; i < n; i ++ ){
X[i] = X[i - 1] + l[i - 1];
}
for(auto x : _d)
W.push_back(x);
for(int i = 0 ; i < n; i ++ ){
A.push_back(mp(X[i] + W[i], i));
B.push_back(mp(X[i] - W[i] ,i));
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
L = _c;
ll li = 0;
ll ri = (ll)1e16;
ll mid;
while(li < ri){
mid = (li + ri) / 2;
if(check(mid)){
ri = mid;
}
else{
li = mid + 1;
}
}
return li;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
204 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
204 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
204 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
204 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
204 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
292 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
204 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
204 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
204 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
204 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
204 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
204 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
204 KB |
n = 5, 4000000000 is a correct answer |
17 |
Incorrect |
0 ms |
204 KB |
n = 10, incorrect answer: jury 1000000343 vs contestant 1000000156 |
18 |
Halted |
0 ms |
0 KB |
- |