玄学+问题转化
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N = 100010;
int a[N];
int f(int x)
{
return x*x;
}
signed main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]=a[i-1]+a[i];
}
int res=0x3f3f3f3f;
for(int i=1;i<=n;i++)
{
for(int j=i+1,k=0;j<=n&&k<100;j++,k++)
{
int t=f(j-i)+f(a[j]-a[i]);
res=min(res,t);
}
}
cout<<res<<endl;
}