QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480190#801. 回文自动机Purslane#0 5ms31604kbC++14870b2024-07-16 09:53:362024-07-16 09:53:36

Judging History

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

  • [2024-07-16 09:53:36]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:31604kb
  • [2024-07-16 09:53:36]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=1e6+10; 
string S;
int n,tot,lst,cnt[MAXN],fail[MAXN],to[MAXN][27],len[MAXN];
vector<int> G[MAXN];
void dfs(int u) {
	for(auto v:G[u]) dfs(v),cnt[u]+=cnt[v];	
	return ;
}
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	tot=1,len[1]=-1,fail[0]=1;
	cin>>S,n=S.size(),S="*"+S;
	lst=1;
	ffor(i,1,n) {
		while(S[i]!=S[i-1-len[lst]]) lst=fail[lst];
		if(to[lst][S[i]-'a']==0) to[lst][S[i]-'a']=++tot,len[tot]=len[lst]+2,fail[tot]=to[fail[lst]][S[i]-'a'];
		lst=to[lst][S[i]-'a'],cnt[lst]++;
	}
	ffor(i,0,tot) if(i!=1) G[fail[i]].push_back(i);
	dfs(1);
	ll ans=0;
	ffor(i,0,tot) if(i!=1) ans=max(ans,1ll*len[i]*cnt[i]*len[i]);
	cout<<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: 5ms
memory: 31604kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

5195

result:

wrong answer expected '5594', found '5195'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%