#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;
long long ans=1e18,lofn;
vector<long long>prf,dep,len;
long long precalc[3010][3010];
long long checkvl(int lend,int rend){
vector<long long>dep2=dep,origd;
long long vl=0,mxpos=0;
for(int i=2;i<=lend;i++){
vl=max(vl,dep2[i]+len[i-1]+dep2[i-1]);
dep2[i]=max(dep2[i],dep2[i-1]+len[i-1]);
}
for(int i=dep.size();--i>rend;){
long long gameover=dep2[i]+len[i-1]+dep2[i-1];
if(vl<gameover)vl=gameover,mxpos=rend;
dep2[i-1]=max(dep2[i-1],dep2[i]+len[i-1]);
}
origd=dep2;
for(int i=lend+1;i<=rend;i++)
dep2[i]=max(dep2[i-1],prf[i]-prf[lend]+dep2[i]);
dep2[lend-1]=-1e18;
long long KY=prf[rend]-prf[lend]+lofn;
int pt=rend;
for(int i=rend;i>lend;i--){
long long THIS=0;
for(int j=i-1;j>=lend;j--){
long long cc=prf[i]-prf[j];
THIS=max(THIS,min(cc,KY-cc)+origd[i]+origd[j]);
}
if(THIS>vl)vl=THIS,mxpos=i;
}
ans=min(ans,vl);
return vl;
}
/*void binsearch(int l){
int L=l+1,R=dep.size()-1;
while(L<=R){
int mid=L+R>>1;
if(checklr(l,mid))
L=mid+1;
else R=mid-1;
}
}*/
void DNC(int l,int r,int opl,int opr){
if(l>r)return;
int mid=l+r>>1,opt=0;
long long VD=1e18;
for(int i=max(mid+1,opl);i<=opr;i++) {
long long k=checkvl(mid,i);
if(VD>k) VD=k,opt=i;
}
DNC(l,mid-1,opl,opt);
DNC(mid+1,r,opt,opr);
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
lofn=c;
dep=len={0};
prf={0,0};
for(auto i:l)
len.push_back(i),
prf.push_back(i);
for(auto i:d)
dep.push_back(i);
memset(precalc,-7,sizeof precalc);
for(int i=1;i<=n;i++)
prf[i]+=prf[i-1],precalc[i][i]=dep[i]-prf[i];
for(int i=n-1;i;i--) for(int j=i+1;j<=n;j++)
precalc[i][j]=max(precalc[i][j-1],dep[j]-prf[j]);
DNC(1,n-1,1,n);
//for(int i=1;i<n;i++)
// binsearch(i);
return ans;
}
Compilation message
shortcut.cpp: In function 'long long int checkvl(int, int)':
shortcut.cpp:10:20: warning: variable 'mxpos' set but not used [-Wunused-but-set-variable]
10 | long long vl=0,mxpos=0;
| ^~~~~
shortcut.cpp:25:9: warning: unused variable 'pt' [-Wunused-variable]
25 | int pt=rend;
| ^~
shortcut.cpp: In function 'void DNC(int, int, int, int)':
shortcut.cpp:48:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid=l+r>>1,opt=0;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
71256 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
9 ms |
71260 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
71292 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
71344 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
71260 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
9 ms |
71260 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
8 ms |
71116 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
8 ms |
71260 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
10 ms |
71256 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
9 ms |
71284 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
71260 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
71364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
9 ms |
71512 KB |
n = 4, 4000000000 is a correct answer |
16 |
Incorrect |
9 ms |
71260 KB |
n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001 |
17 |
Halted |
0 ms |
0 KB |
- |