1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) typedef double db; typedef long long ll; #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) template <class T> inline void cmin(T &a,const T &b){ ((a>b)&&(a=b)); } template <class T> inline void cmax(T &a,const T &b){ ((a<b)&&(a=b)); }
char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int N=1e4+10; const db eps=1e-9; const ll INF=4e18;
int n,h,a,b; int X[N],Y[N]; db L[N],R[N]; db Sqr(db x){ return x*x; } ll dp[N];
int main(){ n=rd(),h=rd(),a=rd(),b=rd(); rep(i,1,n) X[i]=rd(),Y[i]=rd(); rep(i,1,n) { L[i]=min((db)(X[n]-X[i])/2,(db)(h-Y[i])); rep(j,i+1,n) { if(X[j]-X[i]>L[i]+eps) break; db a=1,b=2*(X[i]-X[j]+Y[j]-h),c=Sqr(X[i]-X[j])+Sqr(Y[j]-h); db d=sqrt(b*b-4*a*c); db r=(-b+d)/(2*a); cmin(L[i],r); } L[i]*=2; } rep(i,1,n) { R[i]=min((db)(X[i]-X[1])/2,(db)(h-Y[i])); drep(j,i-1,1) { if(X[i]-X[j]>R[i]+eps) break; db a=1,b=2*(X[j]-X[i]+Y[j]-h),c=Sqr(X[j]-X[i])+Sqr(Y[j]-h); db d=sqrt(b*b-4*a*c); db r=(-b+d)/(2*a); cmin(R[i],r); } R[i]*=2; } dp[1]=1ll*a*(h-Y[1]); rep(i,2,n) { dp[i]=INF; drep(j,i-1,1) { if(X[i]-X[j]>R[i]+eps) break; if(X[i]-X[j]>L[j]+eps) continue; cmin(dp[i],dp[j]+1ll*a*(h-Y[i])+1ll*(X[i]-X[j])*(X[i]-X[j])*b); } } if(dp[n]<INF) printf("%lld\n",dp[n]); else puts("impossible"); }
|