1 条题解

  • -1
    @ 2022-5-12 11:11:15

    不可以CTJ

    //抄代码!!!

    /*****************************************
    备注:
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    int q[N];
    LL sum[N],s[N],dp[N];
    double Y(int j)
    {
    	return dp[j]+s[j]*s[j];
    }
    double Slop(int j1,int j2)
    {
    	return (Y(j2)-Y(j1))/(s[j2]-s[j1]);
    }
    int main()
    {
    	int n,l;
    	cin>>n>>l;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>sum[i];
    		sum[i]+=sum[i-1];
    		s[i]=sum[i]+i;
    	}
    	l++;
    	int h=1,t=1;
    	for(int i=1;i<=n;i++)
    	{
    		while(h<t&&Slop(q[h],q[h+1])<=2.0*(s[i]-l))
    			h++;
    		
    		dp[i]=dp[q[h]]+(s[i]-s[q[h]]-l)*(s[i]-s[q[h]]-l);
    		while(h<t&&Slop(q[t-1],q[t])>Slop(q[t],i))
    		t--;
    		q[++t]=i;
    	}
    	cout<<dp[n];
    }
  • 1

信息

ID
497
时间
1000ms
内存
512MiB
难度
9
标签
递交数
7
已通过
6
上传者