T235569 OKR-Periods of Words

2022/5/4 23:17:51

本文主要是介绍T235569 OKR-Periods of Words,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#include<bits/stdc++.h>using namespace std;int k;char st[1000000+100];int f[1000000+100];int main(){

scanf("%d",&k);

scanf("%s",st);

f[0]=-1;

long long ans=0;

for(int i=1;i<k;i++)

{

int j=f[i-1];f[i]=-1;

while(j>=0&&st[j+1]!=st[i])j=f[j];

if(st[j+1]==st[i])f[i]=j+1;

else 

{

f[i]=-1;

continue;

}

}

 

for(int i=1;i<k;i++)

{

if(f[i]==-1)continue;

int j=i;

while(f[j]!=-1)j=f[j];

f[i]=j;

 

ans+=i-j;

 

}

printf("%lld\n",ans);

return 0;

}



这篇关于T235569 OKR-Periods of Words的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程