请问这为什么RE
查看原帖
请问这为什么RE
460429
Andy_L楼主2023/8/2 12:27

RT,样例对了,全RE

#include <bits/stdc++.h>

using namespace std;

#define int long long

//inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
//inline void write(int x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}

int idx=2;
string s;

const int maxn=1.1e8+100;

int p[maxn];

void read()
{
	char ch=getchar();
	s[0]='-';
	s[1]='|';
	while (ch<'a'||ch>'z') ch=getchar();
	while (ch>='a'&&ch<='z') s[idx++]=ch,s[idx++]='|',ch=getchar();
}

signed main()
{
	read();
	int ans=0;
	for (int i=1,mid=0,r=0;i<=idx;i++)
	{
		if(i<=r) p[i]=min(r-i+1,p[mid*2-i]);
		while (s[i-p[i]]==s[p[i]+i]) p[i]++;
		if(p[i]+i>r) r=p[i]+i-1,mid=i;
		ans=max(ans,p[i]);
	}
	cout<<ans-1<<endl;
	return 0;
}
2023/8/2 12:27
加载中...