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<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "shortcut.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
int n;
LL d[10002];
LL x[10002];
LL c;
struct req
{
LL x;
LL y;
LL k;
};
LL l1,l2,r1,r2;
void hat(req t)
{
LL l3=(t.x-t.k)-t.y;
LL l4=(t.x+t.k)-t.y;
l1=max(l1,l3);
l2=min(l2,l4);
LL r3=(t.y-t.k)+t.x;
LL r4=(t.y+t.k)+t.x;
r1=max(r3,r1);
r2=min(r4,r2);
return;
}
int stug(LL k)
{
l1=-1000000000000000;
l2=-l1;
r1=-1000000000000000;
r2=-r1;
vector<req> V;
for1(i,n)
{
fo(j,i+1,n)
{
if(l1>l2 || r1>r2)
return 0;
if(abs(x[i]-x[j])+d[i]+d[j]>k)
{
if((k-d[i]-d[j]-c)<0)
return 0;
req t;
t.x=x[i];
t.y=x[j];
t.k=k-d[i]-d[j]-c;
hat(t);
}
}
}
for1(i,n)
fo(j,i+1,n)
if((x[i]-x[j])>=l1 && (x[i]-x[j])<=l2 && (x[i]+x[j])>=r1 && (x[i]+x[j])<=r2)
return 1;
return 0;
}
long long find_shortcut(int n_0, vector<int> l, vector<int> d_0, int c_0)
{
c=c_0;
n=n_0;
LL ma=0;
for1(i,n)
{
d[i]=d_0[i-1];
ma=max(ma,d[i]);
}
x[1]=0;
for0(i,l.size()-1)
x[i+2]=x[i+1]+l[i];
LL r=x[n]+2*ma;
LL l1=1;
while(1)
{
if(r==(l1+1))
{
if(stug(l1)==1)
return l1;
return r;
}
if(l1==r)
return l1;
LL m=(l1+r)/2;
if(stug(m)==1)
r=m;
else
l1=(m+1);
}
return 0;
}
# | 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... |