前言
奶龙题,但是细节有点多。
思路
考虑他会怎么走:
-
先向右走再走回来再向左走到游戏结束。
-
先向左走再走回来再向右走到游戏结束。
以下计 为能在 这个位置待几回合即 。
考虑如何扩展,这里以向右为例,向左同理,首先如果有连着的零肯定就不能往后跳了,可以让答案加上 。
交之,唉我怎么假了。
我们需要从一跳回来,但是他跳不回来了,需要特判。
特判之后即可通过本题。
upd:好的如何我又被 hack 了,赛时数据过水。
所以需要特判 , 段的端点是起点,这种情况是可以跳回去的。
代码
signed main(){
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> a >> d;
for(int i = 1; i <= n - 1; ++i) cin >> b[i];
for(int i = 1; i <= n - 1; ++i) s[i] = ((b[i] - 2) / (d << 1));
int L = 0, R = 0, BackR = 0, BackL = 0;
int sum = 0, cnt = 0, f = 0;
for(int i = a; i <= n - 1; ++i){
R += s[i];
if(!f) BackR = max(BackR, sum + s[i]);
sum += s[i];
if(s[i] == 1 && s[i + 1] == 0 && i != a) f = 1;
if(s[i] == 1 && s[i - 1] == 0 && i != a + 1 && i != a) f = 1;
if(s[i] == 0 && s[i + 1] == 0 && i != a) break;
}
sum = 0, cnt = 0, f = 0;
for(int i = a - 1; i >= 1; --i){
L += s[i];
if(!f) BackL = max(BackL, sum + s[i]);
sum += s[i];
if(s[i] == 1 && s[i - 1] == 0 && i != a) f = 1;
if(s[i] == 1 && s[i + 1] == 0 && i != a - 1 && i != a) f = 1;
if(s[i] == 0 && s[i - 1] == 0 && i != a) break;
}
if(s[a] == 0 && s[a + 1] == 0) BackL = BackR = 0;
if(s[a] == 0 && s[a - 1] == 0) BackL = BackR = 0;
int ans = max(R + BackL, L + BackR);
cout << ans << '\n';
return 0;
}

