QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478748#801. 回文自动机liuhengxi0 1ms3712kbC++14882b2024-07-15 10:45:502024-07-15 10:45:51

Judging History

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

  • [2024-07-15 10:45:51]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3712kb
  • [2024-07-15 10:45:50]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
using namespace std;
typedef long long ll;
constexpr int N=1e6+5;
struct node
{
	int tr[26],len,fail;
}a[N];
int n,ind,cur,occ[N];
char s[N];
int main()
{
	scanf("%s",s);
	n=(int)strlen(s);
	a[0].fail=1;
	a[1].len=-1;
	ind=2;
	F(i,0,n)
	{
		if(a[cur].len==i)cur=a[cur].fail;
		while(s[i]!=s[i-a[cur].len-1])cur=a[cur].fail;
		int x=s[i]-'a';
		if(!a[cur].tr[x])
		{
			int u=ind++;
			a[u].len=a[cur].len+2;
			if(cur!=1)
			{
				int v=a[cur].fail;
				while(!a[v].tr[x])v=a[v].fail;
				a[u].fail=a[v].tr[x];
			}
			a[cur].tr[x]=u;
		}
		cur=a[cur].tr[x];
		++occ[cur];
	}
	for(int i=ind;--i>1;)occ[a[i].fail]+=occ[i];
	ll ans=0;
	F(i,2,ind)ans=max(ans,(ll)occ[i]*a[i].len*a[i].len);
	printf("%lld\n",ans);
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

6132

result:

wrong answer expected '5594', found '6132'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%