QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#474185#801. 回文自动机templatetemplate#0 2ms11936kbC++171.5kb2024-07-12 16:33:272024-07-12 16:33:27

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	x=0;
	bool flag=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
	read(x),read(args...);
}
template<typename T>inline void prt(T x){
	if(x>9) prt(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void put(T x){
	if(x<0) putchar('-'),x=-x;
	prt(x);
}
template<typename T>inline void put(char ch,T x){
	put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
	put(ch,x),put(ch,args...);
}
#define N 1000005
char s[N];
int n;
struct Trie{
	int trie[N][26],fail[N],idx,lst,len[N],num[N];
	Trie(){fail[1]=fail[0]=idx=1,len[1]=-1,lst=0;}
	inline int getfail(int x,int i){
		while(i-len[x]-1<0||s[i-len[x]-1]!=s[i]) x=fail[x];
		return x;
	}
	inline void extend(int c,int i){
		int x=getfail(lst,i);
		if(!trie[x][c]){
			len[++idx]=len[x]+2;
			fail[idx]=trie[getfail(x,i)][c];
			trie[x][c]=idx;
		}
		lst=trie[x][c],num[lst]++;
	}
	inline void prework(){
		for(int i=idx;i>1;i--) num[fail[i]]+=num[i];
	}
}P;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;i++) P.extend(s[i]-'a',i);
	P.prework();
	long long ans=0;
	for(int i=2;i<=P.idx;i++) ans=max(ans,1ll*P.num[i]*P.len[i]*P.len[i]);
	put('\n',ans);
	return 0;	
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

3978

result:

wrong answer expected '5594', found '3978'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%