题解:CF676E The Last Fight Between Human and AI

· · 题解

根据代数基本定理,人类能赢当且仅当 P(k)=0。

当 k \ne 0 时:

对其中一篇模数取 998244353、10^9+7、10^9+9 的题解的 Hack:(为了方便起见,我用了 10000 进制)

6 10000
4239
8939
7108
1909
6897
2443
998

:::

当 k=0 时:如果 a_0 还没有填,那么先手必胜;否则判定 a_0 是否为 0 即可。

可以用一个特殊值表示这一位没有填,用string+stringstream 可以避免输入时的复杂处理,记得 clear()。 :::info[Code Time]

#include <bits/stdc++.h>
using namespace std;
const int N=100007,X=0x3f3f3f3f;
int a[N];
mt19937_64 rnd((random_device()()));
typedef unsigned long long li;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    stringstream ss;
    string s;
    int cnt=0;
    for(int i=0;i<=n;i++){
        cin>>s;
        if(s[0]=='?') a[i]=X;
        else ss.clear(),ss<<s,ss>>a[i],cnt++;
    }
    if(k){
        if(cnt==n+1){
            li m=rnd();
            __int128 ans=0;
            for(int i=n;~i;i--) ans=((ans*k+a[i])%m+m)%m;
            cout<<(ans?"No\n":"Yes\n");
        }else cout<<((n&1)?"Yes\n":"No\n");
    }else{
        if(a[0]==X) cout<<((cnt&1)?"Yes\n":"No\n");
        else cout<<(a[0]?"No\n":"Yes\n");
    }
}

:::