【求助】CF#29过不去,WA,求调
  • 板块CF126B Password
  • 楼主JZLs
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/16 18:24
  • 上次更新2023/11/3 03:19:21
查看原帖
【求助】CF#29过不去,WA,求调
925541
JZLs楼主2023/8/16 18:24
#include <iostream>
#include <cstring>

using namespace std;

const int N=2e6+10;
int ne[N];
char s[N];
void kmp(char s[]) {
	int len=strlen(s+1);
	for(int i=2,j=0; i<=len; i++) {
		while(j&&s[i]!=s[j+1]) j=ne[j];
		if(s[i]==s[j+1]) j++;
		ne[i]=j;
	}
}
signed main() {
	gets(s+1);
	int len=strlen(s+1);	
	if(len<3) {
		cout<<"Just a legend";
		return 0;
	}
	kmp(s);
	int ans=0;
	//for(int i=1; i<=len; i++) cout<<ne[i]<<" ";
	//cout<<endl;
	//cout<<len<<endl;
	for(int i=2; i<len; i++)
		if(s[i]==s[len]&&ne[i]<=ne[len]) {
			ans=max(ans,ne[i]);
		}
	if(ans==0) cout<<"Just a legend";
	else for(int i=1; i<=ans; i++) cout<<s[i];
	return 0;
}
2023/8/16 18:24
加载中...