#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,a[MAXN],pos;
ll cost;
map<ll,int>pm;
PII F[MAXN];
void upd(int x,ll a,ll b){
for(;x<=c;x+=x&(-x))
umin(F[x].ff,a),umax(F[x].ss,b);
}
PII tap(int x){
PII res=mp(B,-B);
for(;x;x-=x&(-x))
umin(res.ff,F[x].ff),umax(res.ss,F[x].ss);
return res;
}
vector<ll>opt;
bool ok(ll k){ll K=k-cost;
ll A1=-B,A2=B,B1=-B,B2=B;
for(int i=0;i<=c;i++)
F[i]=mp(B,-B);
for(int i=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();
if(pos>0){
PII res=tap(pos);
umin(A2,xx+res.ff+K);umax(A1,yy+res.ss-K);
umin(B2,xx-res.ss+K);umax(B1,yy-res.ff-K);
}
upd(a[i],xx,yy);
}
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);
if(p<j and x[p]>=xx and x[p]<=yy)return 1;
while(p<j and x[p]<xx)p++;
while(p>0 and x[p-1]>=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]=pm[x[i]-d[i]];
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
n = 4, incorrect answer: jury 80 vs contestant 100 |
2 |
Halted |
0 ms |
0 KB |
- |