这题打了个斜率DP。有点骚。。。
但为什么我的时间不是最快的!
上标:
#include<cstdio>
#include<algorithm>
#define N 150010
#define db double
using namespace std;
int n,a[N],b[N],c[N],f[N],ans=999999999;
int g[N],len,l;
inline int read()
{
int x=0; char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
db ab(int x,int y) {return (db)(a[x]-a[y])/(b[x]-b[y]);}
db ac(int x,int y) {return (db)(a[x]-a[y])/(c[x]-c[y]);}
db ba(int x,int y) {return (db)(b[x]-b[y])/(a[x]-a[y]);}
db bc(int x,int y) {return (db)(b[x]-b[y])/(c[x]-c[y]);}
db ca(int x,int y) {return (db)(c[x]-c[y])/(a[x]-a[y]);}
db cb(int x,int y) {return (db)(c[x]-c[y])/(b[x]-b[y]);}
int main()
{
freopen("acm.in","r",stdin);
freopen("acm.out","w",stdout);
n=read();a[0]=b[0]=c[0]=0;
for (int i=1;i<=n;i++) a[i]=read()+a[i-1];
for (int i=1;i<=n;i++) b[i]=read()+b[i-1];
for (int i=1;i<=n;i++) c[i]=read()+c[i-1];
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && ab(g[l+1],g[l])<=1.0) l++;
f[i]=a[g[l]]+b[i]-b[g[l]];
ans=std::min(ans,f[i]+c[n]-c[i]);
while (len && ab(g[len],g[len-1])>=ab(i,g[len])) len--;
g[++len]=i;
}
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && ac(g[l+1],g[l])<=1.0) l++;
f[i]=a[g[l]]+c[i]-c[g[l]];
ans=std::min(ans,f[i]+b[n]-b[i]);
while (len && ac(g[len],g[len-1])>=ac(i,g[len])) len--;
g[++len]=i;
}
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && ba(g[l+1],g[l])<=1.0) l++;
f[i]=b[g[l]]+a[i]-a[g[l]];
ans=std::min(ans,f[i]+c[n]-c[i]);
while (len && ba(g[len],g[len-1])>=ba(i,g[len])) len--;
g[++len]=i;
}
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && bc(g[l+1],g[l])<=1.0) l++;
f[i]=b[g[l]]+c[i]-c[g[l]];
ans=std::min(ans,f[i]+a[n]-a[i]);
while (len && bc(g[len],g[len-1])>=bc(i,g[len])) len--;
g[++len]=i;
}
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && ca(g[l+1],g[l])<=1.0) l++;
f[i]=c[g[l]]+a[i]-a[g[l]];
ans=std::min(ans,f[i]+b[n]-b[i]);
while (len && ca(g[len],g[len-1])>=ca(i,g[len])) len--;
g[++len]=i;
}
g[len=1]=1,l=1;
for (int i=2;i<n;i++)
{
if (l>len) l=len;
while (l<len && cb(g[l+1],g[l])<=1.0) l++;
f[i]=c[g[l]]+b[i]-b[g[l]];
ans=std::min(ans,f[i]+a[n]-a[i]);
while (len && cb(g[len],g[len-1])>=cb(i,g[len])) len--;
g[++len]=i;
}
printf("%d
",ans);
return 0;
}