Submission #366349

# Submission time Handle Problem Language Result Execution time Memory
366349 2021-02-14T03:55:23 Z YJU Palindromes (APIO14_palindrome) C++14
100 / 100
62 ms 73844 KB
#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 time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2796 KB Output is correct
2 Correct 2 ms 2796 KB Output is correct
3 Correct 2 ms 2796 KB Output is correct
4 Correct 2 ms 2796 KB Output is correct
5 Correct 2 ms 2796 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 2 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 24812 KB Output is correct
2 Correct 17 ms 24812 KB Output is correct
3 Correct 16 ms 24812 KB Output is correct
4 Correct 17 ms 24812 KB Output is correct
5 Correct 20 ms 24812 KB Output is correct
6 Correct 14 ms 18284 KB Output is correct
7 Correct 14 ms 21120 KB Output is correct
8 Correct 2 ms 748 KB Output is correct
9 Correct 5 ms 6380 KB Output is correct
10 Correct 15 ms 21228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 73588 KB Output is correct
2 Correct 51 ms 73588 KB Output is correct
3 Correct 48 ms 73588 KB Output is correct
4 Correct 49 ms 73588 KB Output is correct
5 Correct 62 ms 73604 KB Output is correct
6 Correct 46 ms 65396 KB Output is correct
7 Correct 43 ms 61300 KB Output is correct
8 Correct 6 ms 1140 KB Output is correct
9 Correct 6 ms 1396 KB Output is correct
10 Correct 47 ms 60660 KB Output is correct
11 Correct 46 ms 73844 KB Output is correct
12 Correct 10 ms 8052 KB Output is correct