Submission #262079

# Submission time Handle Problem Language Result Execution time Memory
262079 2020-08-12T10:29:16 Z mohamedsobhi777 Palindromes (APIO14_palindrome) C++14
0 / 100
39 ms 39920 KB
//#include "elephants.h"
#include<bits/stdc++.h>

#define I inline void 

using namespace std ; 

using ld = long double ; 
using ll = long long ; 

const int N = 3e5  + 7 , mod = 1e9 + 7 ; 

int n;
ll ans ; 
string s;
int num , suf ; 

struct node{
	int nxt[26] ; 
	int len ; 
	int num ; 
	int occ ; 
	int lazy ; 
	int suflnk ; 
} tree[N] ; 


bool addL(int pos){
	int cur = suf , curlen = 0 ; 
	int let = s[pos] - 'a' ; 

	while(1){
		curlen = tree[cur].len ;
		if(pos - 1 - curlen >=0 && s[pos - 1 - curlen ] == s[pos])
			break ; 
		cur = tree[cur].suflnk ;
	}

	if(tree[cur].nxt[let]){
		suf = tree[cur].nxt[let] ; 
		tree[suf].lazy++ ; 
		return 0 ; 
	}

	num ++ ;
	suf = num ;
	tree[num].len = tree[cur].len + 2 ; 
	
	tree[cur].nxt[let] = num ;

	tree[num].lazy ++ ;  

	if(tree[num].len == 1){
		tree[num].suflnk = 2 ; 
		tree[num].lazy = 1; 
		return 1 ; 
	}

	while(1){
		cur = tree[cur].suflnk ; 
		curlen = tree[cur].len ; 
		if(pos -1 - curlen >= 0 && s[pos] == s[pos - 1 - curlen ]){
			tree[num].suflnk = tree[cur].nxt[let] ; 
			break ;
		}
	}

	tree[num].num = 1 + tree[tree[num].suflnk].num ; 

	return 1 ; 
}

I init(){
	suf = num = 2 ; 
	tree[1].len = -1 ; 
	tree[2].len = 0 ; 
	tree[1].suflnk = 1 ; 
	tree[2].suflnk = 1 ; 
}

int pal[N] ; 
int vis[N] ; 

int main(){

	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in" , "r" , stdin) ; 
	init() ; 
	cin >> s ; 
	n = (int) s.size() ; 
	for(int i = 0 ;i < n ;i++){
		addL(i) ; 
	}	

	for(int i = num ;i > 2 ;i--){
		int cur = i ; 
		int lz = tree[cur].lazy ; 
		while(cur > 2 && !vis[cur]++ ){		
			vis[cur] = 1; 
			pal[cur]+= lz ; 
			lz+=tree[cur].lazy ; 
			cur = tree[cur].suflnk ;

		}
	}

	for(int i = 3 ;i <= num ;i++){
		ans = max(ans , 1ll * tree[i].len * pal[i] ) ; 
	}

	cout<< ans << endl; 
	return 0 ; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 0 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1664 KB Output is correct
2 Correct 1 ms 1664 KB Output is correct
3 Correct 1 ms 1664 KB Output is correct
4 Correct 1 ms 1664 KB Output is correct
5 Incorrect 1 ms 1664 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 13568 KB Output is correct
2 Correct 12 ms 13568 KB Output is correct
3 Correct 12 ms 13568 KB Output is correct
4 Correct 12 ms 13568 KB Output is correct
5 Incorrect 12 ms 13568 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 39920 KB Output is correct
2 Correct 37 ms 39856 KB Output is correct
3 Correct 39 ms 39808 KB Output is correct
4 Correct 37 ms 39744 KB Output is correct
5 Incorrect 36 ms 39808 KB Output isn't correct
6 Halted 0 ms 0 KB -