#include "shortcut.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
using namespace :: std;
const ll maxn=510;
const ll inf=1e17+900;
ll pos[maxn];
ll farr[maxn];
ll farl[maxn];
ll dr[maxn];
ll dl[maxn];
ll c,n,ans=inf;
vector<ll> l;
vector<ll> d;
ll ERT[maxn][maxn];
ll findANS(ll i,ll j){
if(i==j)return dr[0];
if(i>j)swap(i,j);
if(ERT[i][j]!=0)return ERT[i][j];
ll res=dr[j];
ll sdi=d[i];
ll sdj=d[j];
d[j]=farr[j];
d[i]=farl[i];
ll tol=c+pos[j]-pos[i];
for(ll u=i;u<=j;u++){
for(ll v=u+1;v<=j;v++){
res=max(res,(ll)d[v]+(ll)d[u]+min(pos[v]-pos[u],tol-(pos[v]-pos[u])));
}
}
d[j]=sdj;
d[i]=sdi;
ans=min(ans,max(dr[j],max(dl[i],res)));
ERT[i][j]=res;
return res;
}
long long find_shortcut(int N,vector<int> L,vector<int> D, int C)
{
n=N;
c=C;
for(auto v:L){
l.pb(v);
}
for(auto v:D){
d.pb(v);
}
pos[0]=0;
for(ll i=1;i<n;i++){
pos[i]=pos[i-1]+l[i-1];
}
dl[0]=d[0];
farl[0]=d[0];
for(ll i=1;i<n;i++){
farl[i]=max(d[i],farl[i-1]+l[i-1]);
dl[i]=max(dl[i-1],farl[i-1]+l[i-1]+d[i]);
}
dr[n-1]=d[n-1];
farr[n-1]=d[n-1];
for(ll i=n-2;i>=0;i--){
farr[i]=max((ll)d[i],farr[i+1]+l[i]);
dr[i]=max(dr[i+1],farr[i+1]+l[i]+d[i]);
}
ll pj=n-1;
for(ll i=n-2;i>=0;i--){
while(pj>i+1 && findANS(i,pj)>findANS(i,pj-1))pj--;
findANS(i,pj);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
380 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
376 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
380 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
2 ms |
376 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
2 ms |
376 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
6 ms |
376 KB |
n = 10, 1000000343 is a correct answer |
18 |
Incorrect |
2 ms |
376 KB |
n = 10, incorrect answer: jury 3189 vs contestant 3392 |
19 |
Halted |
0 ms |
0 KB |
- |