POI2006 OKR-Periods of Words

POI 2006 OKR-Periods of Words

Solution:

Wating...

Code:

#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n;
char s[N];
int Next[N];
int vis[N];
typedef long long ll;
void get_next(char p[],int lenp){
	int j=0;
	for(int i=2;i<=lenp;++i){
		while(j&&p[j+1]!=p[i])j=Next[j];
		if(p[j+1]==p[i]){j++;}
		Next[i]=j;
	}
}
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	get_next(s,n);
	ll sum=0;
	for(int i=1;i<=n;++i){
		int pos=i;
		if(Next[Next[i]]!=0){
			vis[i]=min(Next[i],vis[Next[i]]);
		}
		else{
			vis[i]=Next[i];
		}
		if(vis[i])sum+=(i-vis[i]);
	}
	printf("%lld\n",sum);
	return 0;
}
上一篇:从零开始到改写并运行object_detection_tutorial.ipynb


下一篇:vSAN集群 无法识别磁盘处理