本地AC 提交WA?

P3435 [POI2006] OKR-Periods of Words

Dreamweaver @ 2021-07-12 14:47:21

#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define inf 0x3f3f3f3f
#define re register
#define maxn 1000010
#define int long long
#define Orz cout<<"stO %王队% Orz"<<'\n';
int n,next[maxn];
string a;
int ans;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0'; ch=getchar();}
    return x*f;
}
signed main()
{
    cin>>n;
    cin>>a;
    a=' '+a;
    for(re int i=2,j=0;i<=n;++i)
    {
        while(j&&a[i]!=a[j+1])  j=next[j];
        if(a[i]==a[j+1]) j++;
        next[i]=j;
        if(next[i])
        {
            int o=i-next[i];
            ans+=((i/o)*o);
            if(((i/o)*o)==i)    ans--;
        }
    }
    cout<<ans<<'\n';
    return ~~(0^0);
}

本地和评测机输出不一样?

2 是样例,但是这一份代码会WA


|