比赛 2024暑假C班集训7 评测结果 AAAAAAAAWWWWWWWWWAWW
题目名称 游戏 最终得分 45
用户昵称 健康铀 运行时间 0.106 s
代码语言 C++ 内存使用 4.90 MiB
提交时间 2024-07-07 11:54:04
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int P = 13331;
unsigned long long f1[N], f2[N], p[N],sk[N],ans=1,n,k,sum;
string a; 
int d[N],maxx;
char s[N];
int abs(unsigned long long a1,unsigned long long b,unsigned long long p1){
    int ans1=1%p1;
    for(;b;b>>=1){
        if(b&1)ans1=(unsigned long long)a1*ans1%p1;
        a1=(unsigned long long)a1*a1%p1;
    }
    return ans1%p1;
}
int main()
{
    freopen("rehearse.in","r",stdin);
    freopen("rehearse.out","w",stdout);
    cin>>n>>k;
    if(k==1){
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        p[0] = 1;
        f1[0] = f2[n + 1] = 0;
        for(int i = 1; i <= n; ++i)
        {
            f1[i] = f1[i - 1] * P + s[i] - 'a' + 1;
            f2[n - i + 1] = f2[n - i + 2] * P + s[n - i + 1] - 'a' + 1;
            p[i] = p[i - 1] * P;
        }
        int ans = 1;
        d[1] = 1;
        for(int r = 2; r <= n; ++r) 
        {
            for(int j = min(d[r - 1] + 2, r); j; --j) 
            {
                int l = r - j + 1;
                unsigned long long hs1 = f1[r] - f1[l - 1] * p[r - l + 1];
                unsigned long long hs2 = f2[l] - f2[r + 1] * p[r - l + 1];
                if(hs1 == hs2) { d[r] = j; break; }               
            }
            if(d[r]%2==1)
            ans = max(ans, d[r]);
        }
        cout<<ans%19930726;
        return 0; 
    }
    if(n>10000){
        cout<<-1;
        return 0;
    }
    cin>>a;
    for(int i=1;i<=n-1;i++){
        int l=i,r=i,z=1;
        while(a[l]==a[r]){
            sum++;
            p[z]++;
            l--;
            r++;
            z+=2;
        }
    }
    p[1]+=2;
    if(sum<k){
        cout<<-1;
        return 0;
    }
    int res=0;
    for(int i=n;i>=1;i--){
        if(res+p[i]<k){
            ans=ans*abs(i,p[i],19930726)%19930726;
            res+=p[i];
        }
        else{
            ans=ans*abs(i,k-res,19930726)%19930726;
            break;
        }
    }
    cout<<ans;
	return 0;
}