#include "shortcut.h"
#include "bits/stdc++.h"
#define MAXN 300009
#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 B=1e18;
vector<ll>x;
vector<int>d;
int n,c,pos;
pair<int,PII>a[MAXN];
ll cost,K;
map<ll,int>pm;
vector<ll>opt;
bool ok(ll k){K=k-cost;
ll A1=-B,A2=B,B1=-B,B2=B;
PII res=mp(B,-B);
for(int i=0,p=0;i<n;i++){
ll xx=x[i]-d[i],yy=x[i]+d[i];
pos=lower_bound(all(opt),x[i]+d[i]-k)-opt.begin();
while(p<pos)umin(res.ff,a[p].ss.ff),umax(res.ss,a[p].ss.ss),p++;
umin(A2,xx+res.ff+K);umax(A1,yy+res.ss-K);
umin(B2,xx-res.ss+K);umax(B1,yy-res.ff-K);
}
if(A1>A2 or B1>B2)return 0;
for(int j=0,p=0;j<n;j++){
ll xx=max(A1-x[j],x[j]-B2),yy=min(A2-x[j],x[j]-B1);
while(p>0 and x[p-1]>=xx)p--;
if(p<j and x[p]>=xx and x[p]<=yy)return 1;
while(p<j and x[p]<xx)p++;
}
return 0;
}
long long find_shortcut(int N,vector<int> l,vector<int>D, int c_edge){
d=D;cost=c_edge;n=N;x.resize(n);for(int i=0;i<n;i++)x[i]=0;pm.clear();c=0;
for(int i=0;i<n-1;i++)x[i+1]=x[i]+l[i];
for(int i=0;i<n;i++)pm[x[i]-d[i]]=1;
tr(it,pm)it->ss=++c,opt.pb(it->ff);
for(int i=0;i<n;i++)a[i]=mp(pm[x[i]-d[i]],mp(x[i]-d[i],x[i]+d[i]));
sort(a,a+n);ll st=1,en=ll(1e15);
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 |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
256 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
364 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |