为什么一个赋值能 TLE
  • 板块CF126B Password
  • 楼主Fuxh_18
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/7/23 11:19
  • 上次更新2024/7/23 12:12:01
查看原帖
为什么一个赋值能 TLE
627732
Fuxh_18楼主2024/7/23 11:19
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+1;
char s[N];
int nxt[N],mx;//这一行,如果我给 mx 赋一个 -1,就会 TLE。不赋值,就 AC 了
int main(){
	cin>>s+1;
	int len=strlen(s+1);
	for(int i=2,j=0;i<=len;i++){
		while(j&&s[i]!=s[j+1]){
			j=nxt[j];
		}
		if(s[i]==s[j+1]){
			j++;
		}
		nxt[i]=j;
		if(i!=len){
			mx=max(mx,nxt[i]);
		}
	}
	int f=nxt[len];
	if(!f){
		cout<<"Just a legend"<<endl;
	}
	else{
			while(f>mx){
				f=nxt[f];
			} 
			if(!f){
				cout<<"Just a legend"<<endl;
			}
			else{
				for(int i=2;i<len;i++){
					if(f==nxt[i]){
						for(int j=i-nxt[i]+1;j<=i;j++){
							cout<<s[j];
						}
						cout<<endl;
						exit(0);
					}
				}
			}
	}
	return 0;
}

第六行有疑问。

2024/7/23 11:19
加载中...