求大佬hack

P3435 [POI2006] OKR-Periods of Words

Moros @ 2024-02-22 15:28:20

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAXN=1e6+10;
const int mod=1e9+7;
int pmt[MAXN];
ll ans;
inline void get_pmt(const string &s){
    for(int i=1,j=0;i<s.length();i++){
        while(j&&s[i]!=s[j])j=pmt[j-1];
        if(s[i]==s[j])j++;
        pmt[i]=j;
    }
}
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s;
    cin>>s;
    get_pmt(s);
    int j=0;
    for(int i=0;i<s.length();i++){
        j=i+1;
        while(pmt[j-1])j=pmt[j-1];
        if(pmt[i])pmt[i]=j;
        ans+=i-j+1;
    }
    cout<<ans;
    return 0;
}

感觉自己的做法可能有点问题,但是找不出来


by aru123 @ 2024-03-27 11:53:38

要求A是QQ的前缀,Q是A的真前缀至少得满足len(A)/2 <= len(Q) < len(A)


|