#include "shortcut.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
typedef long long ll;
int n;
vector<int> l,d;
int c;
vector<ll> v,p,q;
const ll inf=1e18;
bool check(ll D){
ll a1=-inf,a2=inf,a3=-inf,a4=inf;
// a1,a2 => X+Y, a1,a3 => O > X
vector<int> dq;
int l=0,a=0;
ll mp=-inf,mq=-inf;
for(int i=0;i<n;i++){
while(l<dq.size() && q[dq[l]]+p[i]>D){
for(;a<=dq[l];a++){
mp=max(mp,p[a]);
mq=max(mq,q[a]);
}
l++;
}
a1=max(a1,mp+p[i]+c-D);
a2=min(a2,-mq-q[i]+D-c);
a3=max(a3,mp+q[i]+c-D);
a4=min(a4,-mq-p[i]+D-c);
while(dq.size()>l && q[dq.back()]<=q[i]){
dq.pop_back();
}
dq.push_back(i);
}
if(a1>a2 || a3>a4){
return 0;
}
int l1=-1,r1=n,l2=-1,r2=n;
for(int i=0;i<n;i++){
while(l1+1<=i && v[l1+1]<=a2-v[i]){
l1++;
}
while(l2+1<=i && v[l2+1]<=a4+v[i]){
l2++;
}
while(r1-1>=0 && v[r1-1]>=a1-v[i]){
r1--;
}
while(r2-1>=0 && v[r2-1]>=a3+v[i]){
r2--;
}
int b=min(l1,l2),w=max(r1,r2);
if(b>=w && w<=i){
return 1;
}
}
return 0;
}
ll find_shortcut(int N, vector<int> L, vector<int> D, int C)
{
n=N;
l=L;
d=D;
c=C;
v.resize(n);
p.resize(n);
q.resize(n);
for(int i=0;i<n;i++){
if(i){
v[i]=l[i-1];
v[i]+=v[i-1];
}
p[i]=v[i]+d[i];
q[i]=d[i]-v[i];
}
ll le=0,r=inf;
while(r>le){
ll m=(le+r)/2;
if(check(m)){
r=m;
}
else{
le=m+1;
}
}
return le;
}
Compilation message
shortcut.cpp: In function 'bool check(ll)':
shortcut.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(l<dq.size() && q[dq[l]]+p[i]>D){
| ~^~~~~~~~~~
shortcut.cpp:33:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
33 | while(dq.size()>l && q[dq.back()]<=q[i]){
| ~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
300 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
304 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
300 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
304 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
300 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
1 ms |
324 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3115 |
19 |
Halted |
0 ms |
0 KB |
- |