QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480569#801. 回文自动机hy233#0 2ms10212kbC++141.0kb2024-07-16 16:38:332024-07-16 16:38:33

Judging History

你现在查看的是最新测评结果

  • [2024-07-16 16:38:33]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:10212kb
  • [2024-07-16 16:38:33]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
const ll mod=1e9+7;
inline int rd()
{
	int x=0; bool f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-') f=0;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+(ch^48);
	return f?x:-x;
}
char s[N];
int son[N][26],len[N],fail[N],cnt=1;
int num[N];
int getfail(int p,int i)
{
	while(s[i-len[p]-1]!=s[i]) p=fail[p];
	return p;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	len[0]=-1;
	fail[0]=1;
	int p=0;
	for(int i=1;i<=n;i++)
	{
		p=getfail(p,i);
		if(!son[p][s[i]-'a'])
		{
			fail[cnt]=son[getfail(fail[p],i)][s[i]-'a'];
			son[p][s[i]-'a']=++cnt;
			len[cnt]=len[p]+2;
		}
		p=son[p][s[i]-'a'];
		num[p]++;
	}
	vector<int> vec;
	for(int i=0;i<=cnt;i++)
		vec.push_back(i);
	sort(vec.begin(),vec.end(),[&](int i,int j){ return len[i]>len[j]; });
	for(auto x:vec)
		num[fail[x]]+=num[x];
	ll ans=0;
	for(int i=2;i<=cnt;i++)
		ans=max(ans,1ll*num[i]*len[i]*len[i]);
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 10212kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

9619

result:

wrong answer expected '5594', found '9619'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%