QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478729#801. 回文自动机liuhengxi0 0ms5756kbC++14813b2024-07-15 10:39:452024-07-15 10:39:45

Judging History

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

  • [2024-07-15 10:39:45]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:5756kb
  • [2024-07-15 10:39:45]
  • 提交

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;
			a[u].fail=cur!=1?a[a[cur].fail].tr[x]:0;
			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: 0ms
memory: 5756kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

5195

result:

wrong answer expected '5594', found '5195'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%