Submission #366349

#TimeUsernameProblemLanguageResultExecution timeMemory
366349YJUPalindromes (APIO14_palindrome)C++14
100 / 100
62 ms73844 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
 
struct node{
	ll length,start,end,cnt;
	ll insert_edge[26];
	ll suffix_edge;
};
 
node tree[N];
string s;
ll ptr,cur;
 
void insert(ll id){
	ll tmp=cur;
	while(1){
		if(id-tree[tmp].length>=1&&s[id]==s[id-tree[tmp].length-1])break;
		tmp=tree[tmp].suffix_edge;
	}
	if(tree[tmp].insert_edge[s[id]-'a']!=0){
		cur=tree[tmp].insert_edge[s[id]-'a'];
		++tree[tree[tmp].insert_edge[s[id]-'a']].cnt;
		return ;
	}
	
	//build new node
	
	++ptr;
	tree[tmp].insert_edge[s[id]-'a']=ptr;
	tree[ptr].length=tree[tmp].length+2;
	tree[ptr].end=id;
	tree[ptr].start=id-tree[ptr].length+1;
	tree[ptr].cnt=1;
	
	// suffix_edge
	
	tmp=tree[tmp].suffix_edge;
	cur=ptr;
	if(tree[cur].length==1){
		tree[cur].suffix_edge=2;
		return; 
	}
	while(1){
		if(id-tree[tmp].length>=1&&s[id]==s[id-tree[tmp].length-1])break;
		tmp=tree[tmp].suffix_edge;
	}
	tree[cur].suffix_edge=tree[tmp].insert_edge[s[id]-'a'];
}
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	tree[1].length=-1;
	tree[1].suffix_edge=1;
	tree[2].length=0;
	tree[2].suffix_edge=1;
	ptr=2;
	cur=1;
	cin>>s;
	REP(i,SZ(s))insert(i);
	ll ans=0;
	for(int i=ptr;i>=3;i--){
		tree[tree[i].suffix_edge].cnt+=tree[i].cnt;
		ans=max(ans,tree[i].length*tree[i].cnt);
	}
	cout<<ans<<"\n";
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...