QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64726#801. 回文自动机LinkZelda#0 3ms3516kbC++141.0kb2022-11-25 14:09:262022-11-25 14:09:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 14:09:29]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:3516kb
  • [2022-11-25 14:09:26]
  • 提交

answer

#include<bits/stdc++.h> 
#define pr pair<int,int>
#define eps 1e-7
#define int long long

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int N=1000005;
char s[N];
int len[N],tr[26][N],fail[N],val[N],tot;

void init()
{
	len[tot=1]=-1;
	fail[1]=fail[0]=1;
}

int n,last;

int getfail(int cur,int x)
{
	while(s[x-len[cur]-1]!=s[x])
		cur=fail[cur];
	return cur;
}

void ins(int x)
{
	int cur=getfail(last,x);
	if(!tr[s[x]-'a'][cur])
	{
		++tot;len[tot]=len[cur]+2;
		fail[tot]=tr[s[x]-'a'][getfail(fail[cur],x)];
		tr[s[x]-'a'][cur]=tot;
	}
	last=tr[s[x]-'a'][cur];
	val[last]++;
}

int ans;

signed main()
{
	scanf("%s",s+1);n=strlen(s+1);init();
	for(int i=1;i<=n;i++)
		ins(i);
	for(int i=tot;i>=0;i--)
		val[fail[i]]+=val[i];
	for(int i=0;i<=tot;i++)
		ans=max(ans,len[i]*len[i]*val[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: 3ms
memory: 3516kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

35000

result:

wrong answer expected '5594', found '35000'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%