比赛 2026.9.12 评测结果 AAWAAATTAA
题目名称 字符串游戏 最终得分 70
用户昵称 exil 运行时间 2.063 s
代码语言 C++ 内存使用 3.77 MiB
提交时间 2026-09-12 12:11:36
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
int b[2005];
int p[2005];
signed main(){
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a;
    cin>>a;
    int n;
    cin>>n;
    string s="";
//    int jjj=0;
//    for(int i = 1;i<a.length();i++){
//        while(jjj>0 && a[jjj]!=a[i]){
//            jjj=b[jjj-1];
//        }
//        if(a[jjj]==a[i])jjj++;
//        b[jjj]=jjj;
//       
//    }
    
    int ans=0;
    for(int i = 0;i<a.length();i++){
        s=s+a[i];     
        string e="";
        int cnt=n%s.length()-1,re=0;
        for(int j = 0;j<n;j++){
            e=s[cnt]+e;
            cnt--;
            if(cnt<0)cnt=s.length()-1;
        }
        
        for(int j = 0;j<e.length();j++){
            if(e[j]==a[0]){
                for(int h = 0;h<min(e.length(),a.length());h++){
                    if(a[h]!=e[j+h])break;
                    re++;
                }
            }
        }
        
        ans=max(ans,re);
        //cout<<e<<endl;
        
        
        
        
        
    }
    cout<<ans;
    return 0;
}