AT_abc128_f
[ABC128F] Frog Jump
大意
有一排荷花漂浮于水中,用它们表示一个数列
进行下列操作:
选择两个数
不断执行:设
每次到达一个
-
若
y = n-1 游戏结束。 -
若
y \not= n-1 且y 点有荷花,你的分数加上s_{i} 。 -
若
y \not= n-1 但否则你淹死,得分-INF ,游戏结束。
思路
我们考虑每一次会跳到哪个位置。
我们知道,最后我们一定要跳到
由于无论怎么跳我们都不能跳出边界,所以
所以我们枚举
我们再次考虑每一次会跳到哪个位置。我们可以发现,是两个很明显的等差数列,且只和
所以当
当然,在枚举 break。若 break。
代码
/*////////ACACACACACACAC///////////
. CCode by Ntsc .
. Fancy Chargcy .
/*////////ACACACACACACAC///////////
#include<bits/stdc++.h>
#define int long long
#define db double
#define rtn return
using namespace std;
const int N=1e5+5;
const int M=1e5;
const int Mod=1e5;
const int INF=1e5;
int n,m,ans;
int a[N],b[N];
signed main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<=n-3;i++){
int res=0;
for(int k=1;k<=(n-1)/i;k++){
int A=n-1-k*i;
if(A<=i||(A%i==0&&A/i<=k))break;
res+=a[k*i]+a[n-1-k*i];
ans=max(ans,res);
}
}
cout<<ans<<endl;
return 0;
}