暴力代码,j只枚举436位就过掉了,此题数据是否过水
随机化没用的上
#include<bits/stdc++.h>
#define _for(i,x,y) for(int i = (x);i<=(y);i ++)
#define For(i,x,y) for(int i = (x);i<=(y);i +=rand()%2+1)
using namespace std;
typedef long long ll;
const int N = 50010;
const ll INF = LONG_LONG_MAX;
ll f[N];
ll c[N];
int n,L;
int main(){
srand(time(NULL));
scanf("%d%d",&n,&L);
_for(i,1,n){scanf("%lld",&c[i]);c[i] += c[i-1];}
_for(i,0,n)f[i] = INF;
f[0] = 0;
_for(i,1,n){
_for(j,max(0,i-436),i-1){
f[i] = min(f[i],f[j] + (L-(i - j - 1 + c[i] - c[j])) * (L-(i - j - 1 + c[i] - c[j])) );
}
}
printf("%lld\n",f[n]);
return 0;
}