CF5555C

· · 题解

第一眼以为博弈论,吓死了

我们模拟几次 Alice 的行走,或者简单想一下就会发现,Alice 的轨迹是上下两段只有端点重合的线段(但是你不能让上面那段的左端点和下面那段的右端点重合)。

而 Alice 走完之后,矩阵中有数的地方只剩下了两块(也可能是一块),第一块在第一行,从第 i 个数到第 n 个数,i 可以取 [2,n+1];第二块在第二行,从第 1 个数到第 i-2 个数,两段中的 i 相同。

具体的可以看样例解释第一幅图,就是一个 i=3 的情况。

这时,Bob 只有两种选择,即选两块中的一块,因为他如果选择拿第二块,或者说拿第二块中的某些数,就会早早往下,这时候他就回不去第一行了。如果拿第一块也拿不到第二块,道理差不多。

所以咱们可以枚举 i ,取两块中的 \max(因为这个时候是 Bob在选),然后再对这 n 个 \max 取 \min(因为这个时候是 Alice 在选)。

代码:


// Problem: C. Coin Rows
// Contest: Codeforces - Educational Codeforces Round 112 (Rated for Div. 2)
// URL: https://codeforces.ml/contest/1555/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define M 100005
const int inf=1e15;
int n,m,k,a[M],T,suma[M],ans,sumb[M];
signed main()
{
    cin>>T;
    while(T--)
    {
        cin>>n,suma[n+1]=0,ans=inf;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=n;i>=1;i--) suma[i]=suma[i+1]+a[i];
        for(int i=1;i<=n;i++) cin>>a[i],sumb[i]=sumb[i-1]+a[i];
        for(int i=0;i<n;i++) ans=min(ans,max(sumb[i],suma[i+2]));
        cout<<ans<<endl;
    }
    return 0;
}