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 "shortcut.h"
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const ll BIG=1e18;
vector<ll>x;
vector<int>d;
int n;
ll cost;
set<ll>a,b;
bool ok(ll k){
ll A=-BIG,B=BIG,C=-BIG,D=BIG,xx,yy;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
xx=x[i]+x[j],yy=x[j]-x[i];
if(d[i]+d[j]+x[j]-x[i]<=k)
continue;
ll val=k-d[i]-d[j]-cost;
if(val<0)return 0;
umax(C,yy-val);umin(D,yy+val);
umax(A,xx-val);umin(B,xx+val);
}
if(A>B or C>D)return 0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
xx=x[i]+x[j],yy=x[j]-x[i];
if(A<=xx and xx<=B and C<=yy and yy<=D)
return 1;
}
return 0;
}
long long find_shortcut(int N,vector<int> l,vector<int>D, int c){
d=D;cost=c;n=N;x.resize(n);for(int i=0;i<n;i++)x[i]=0;
for(int i=0;i<n-1;i++)
x[i+1]=x[i]+l[i];
ll st=0,en=ll(1e10);
while(st+1<en){
ll mid=(st+en)>>1;
if(ok(mid))
en=mid;
else
st=mid;
}
if(ok(st))return st;
return en;
}
# | 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... |