最后一个点WA了,求大佬
查看原帖
最后一个点WA了,求大佬
764378
lybhbslsd123楼主2023/9/3 15:54
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int nex[1111111]={0};
int main()
{
	int n;
	string str;
	cin>>n>>str;
	int j=0;
	for(int i=1;i<n;i++)
	{
		if(str[i]==str[j])
		{
			j++;
			nex[i]=j;
		}
		else{
			if(j==0)
			{
				nex[i]=0;
			}
			else{
				j=nex[j-1];
			}
		}
	}
	cout<<n-nex[n-1]<<endl;
	return 0;
}


2023/9/3 15:54
加载中...