QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#481175#801. 回文自动机wdnmdwrnmmp#0 4ms29864kbC++141.2kb2024-07-16 21:07:552024-07-16 21:07:56

Judging History

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

  • [2024-07-16 21:07:56]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:29864kb
  • [2024-07-16 21:07:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

namespace pam{
	const int N=1e6+5;
	string str;
	int s[N][26], fa[N], len[N], cnt[N], tot=1;
	vi G[N];
	int getfa(int u,int pos){
		while(str[pos-len[u]-1]!=str[pos]){
			u=fa[u];
		}
		return u;
	}
	int ins(int u,int pos){
		int c=str[pos]-'a';
		u=getfa(u, pos);
		if(!s[u][c]){
			s[u][c]=++tot;
			len[s[u][c]]=len[u]+2;
			fa[s[u][c]]=getfa(fa[u], pos);
			if(fa[s[u][c]]==0){
				fa[s[u][c]]=1;
			}
		}
		return s[u][c];
	}
	void dfs(int u){
		for(int v:G[u]){
			dfs(v);
			cnt[u]+= cnt[v];
		}
	}
	void solve(string _str){
		str=_str;
		len[0]=-1;
		int cur=0;
		rep(i,0,(int)str.size()-1){
			cur=ins(cur, i);
			cnt[cur]++;
		}
		rep(i,1,tot){
			G[fa[i]].pb(i);
		}
		dfs(0);
		long long ans=0;
		rep(i,1,tot){
			ans=max(ans, (long long)len[i]*len[i]*cnt[i]);
		}
		cout<< ans <<'\n';
	}
}
signed main(){
  	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  	
  	string s; cin>>s;
  	pam::solve(s);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 29864kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

3978

result:

wrong answer expected '5594', found '3978'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%