#include <bits/stdc++.h>
#include "shortcut.h"
//colocar grader
#define MAX 1000010
#define INF 1000000000000000000LL
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;
int N, C;
lli L[MAX];
lli D[MAX];
lli sL[MAX];
lli mxLeft[MAX];
lli mxRight[MAX];
lli prefixDist[MAX];
lli suffixDist[MAX];
lli dist(int i, int j) { return sL[j - 1] - sL[i - 1]; }
void init()
{
for(int g = 1 ; g <= N - 1 ; g++)
sL[g] = sL[g - 1] + L[g];
for(int g = 1 ; g <= N ; g++)
mxLeft[g] = max(mxLeft[g - 1] + L[g - 1] , D[g]);
for(int g = N ; g >= 1 ; g--)
mxRight[g] = max(mxRight[g + 1] + L[g] , D[g]);
for(int i = 1 ; i <= N ; i++)
{
suffixDist[i] = suffixDist[i + 1];
for(int j = i + 1 ; j <= N ; j++)
suffixDist[i] = max(suffixDist[i] , D[i] + dist(i , j) + D[j]);
}
for(int i = 1 ; i <= N ; i++)
{
prefixDist[i] = prefixDist[i + 1];
for(int j = i - 1 ; j >= 1 ; j--)
prefixDist[i] = max(prefixDist[i] , D[i] + dist(j , i) + D[j]);
}
}
long long int find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
for(int g = 0 ; g < n - 1 ; g++) L[g + 1] = l[g];
for(int g = 0 ; g < n ; g++) D[g + 1] = d[g];
init();
lli ans = INF;
for(int i = 1 ; i <= n ; i++)
{
for(int j = i + 1 ; j <= n ; j++)
{
lli ansIJ = -1;
ansIJ = max(prefixDist[i] , suffixDist[j]);
//if(i != 2 || j != 3) continue;
//printf("i = %d j = %d\n",i,j);
lli cnt = dist(i , j);
for(int myPoint = i ; myPoint <= j ; myPoint++)
{
lli distance;
if(myPoint != i)
{
distance = dist(i , myPoint);
distance = min(distance , c + cnt - distance);
ansIJ = max(ansIJ , mxLeft[i] + distance + D[myPoint] );
//printf("my = %d %lld %lld %lld\n",myPoint,mxLeft[i], distance,D[myPoint]);
}
for(int g = i + 1 ; g < j ; g++)
{
if(g == myPoint) continue;
distance = dist(g , myPoint);
if(distance < 0) distance = -distance;
distance = min(distance , c + cnt - distance);
ansIJ = max(ansIJ , D[g] + distance + D[myPoint] );
}
if(myPoint != j)
{
distance = dist(myPoint , j);
distance = min(distance , c + cnt - distance);
ansIJ = max(ansIJ , D[myPoint] + distance + mxRight[j] );
//printf("- my = %d %lld %lld %lld\n",myPoint,mxRight[j], distance,D[myPoint]);
}
}
//ansIJ = max(ansIJ , mxLeft[i - 1] + L[i - 1] + D[i]);
//ansIJ = max(ansIJ , mxRight[j + 1] + L[j] + D[j]);
ansIJ = max(ansIJ , min(cnt , (long long int) c) + mxRight[j] + mxLeft[i]);
//printf("------------------------------ i = %d j = %d %d\n",i,j,ansIJ);
ans = min(ans , ansIJ);
}
}
return ans;
}
/*int main()
{
scanf("%d %d",&N,&C);
vector<int> dd(N), ll(N - 1);
for(int g = 0 ; g < N - 1 ; g++)
scanf("%d",&ll[g]);
for(int g = 0 ; g < N ; g++)
scanf("%d",&dd[g]);
printf("%lld\n",find_shortcut(N , ll , dd , C));
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
n = 4, incorrect answer: jury 80 vs contestant 30 |
2 |
Halted |
0 ms |
0 KB |
- |