This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "shortcut.h"
using namespace std;
const int N=502;
long long dis[N][N],mx[N][N],mx1[N][N];
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
if (n>500)
return 0;
for (int i=0;i<n;i++)
{
mx[i][i]=d[i];
mx1[i][i]=d[i];
}
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
dis[i][j]=dis[i][j-1]+l[j-1];
mx[i][j]=max(mx[i][j-1],dis[i][j]+d[j]);
}
}
for (int i=0;i<n;i++)
{
for (int j=i-1;j>=0;j--)
{
mx1[j][i]=max(mx1[j+1][i],dis[j][i]+d[j]);
}
}
long long ans=1e18;
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
long long maxx=0;
for (int q=0;q<n;q++)
{
long long cur=0;
if (q==j)
{
cur= mx[j][n-1];
}
else if (q<=j)
cur= d[q]+mx[j][n-1]+(min(dis[q][j],dis[i][q]+c));
if (q==i)
cur= mx1[0][i];
else if (q>=i)
cur= max(cur,d[q]+mx1[0][i]+min(dis[i][q],dis[q][j]+c));
if (q>=i&&q<=j&&dis[q][j]+c<dis[i][q])
{
int low=i,high=q-1,mid;
long long x=dis[q][j]+c;
while (low<=high)
{
mid= (low+high)/2;
if (x+dis[i][mid]<dis[mid][q])
{
cur=max(cur,x+dis[i][mid]+d[mid]+d[q]);
low=mid+1;
}
else
{
high=mid-1;
cur=max(cur,dis[mid][q]+d[q]+d[mid]);
}
}
}
if (i==0&&j==2)
cout <<cur<<endl;
maxx=max(maxx,cur);
}
ans=min(ans,maxx);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |