求助
查看原帖
求助
340502
MattL卧室奶龙楼主2021/10/5 20:30

不知为啥,最后一个点WA了

最后一个点是 10610^6 个a,输出是 10610^6

求解释?

赛时代码学校评测机竟然判我TLE

#include<bits/stdc++.h>
using namespace std;
inline long long read()
{
	long long x=0,f=1;
	char t=getchar();
	while(t<'0'||t>'9'){if(t=='-')f=-1;t=getchar();}
	while(t>='0'&&t<='9'){x=(x<<3)+(x<<1)+t-48;t=getchar();}
	return x*f;
}
int n;
bool find_xh;
string s,xh,t;
char tt;
int main()
{
//	freopen("string.in","r",stdin);
//	freopen("string.out","w",stdout);
	n=read();
//	tt=getchar();
//	while(islower(tt))
//	{
//		s=s+t;
//		tt=getchar();
//	}
cin>>s;
	for(register int i=0;i<s.size();++i)
	{
		if(find_xh)
		{
			t=t+s[i];
			if(s[i]!=xh[i%xh.size()])
			{
				find_xh=false;
				xh=xh+t;
				t="";
			}
		}
		else
		{
			if(s[i]==xh[0])
			{
				find_xh=true;
				t=s[i];
			}
			else
			{
				xh=xh+s[i];
			}
		}
	}
	printf("%d\n",xh.size());
		
	return 0;
}
/*
16
abcabcnnabcabcnn
*/
2021/10/5 20:30
加载中...