This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
const int inf = 0x3f3f3f3f ;
const int MAXN = 1010 ;
const int ALF = 30 ;
const int SZTRIE = MAXN*MAXN ;
using namespace std ;
//Se der errado, checar o limite da trie
int n, trie[SZTRIE][ALF] , nodes ;
ll qtd[SZTRIE] , qtdTam[MAXN] ;
char str[MAXN] ;
bool s[MAXN][MAXN] ;
void add(char str[] , int l , int r)
{
int cur = 0 ;
for(int i = l ; i < r ; i++ )
{
int c = str[i] - 'a' ;
if( trie[cur][c] == 0 ) trie[cur][c] = ++nodes ;
cur = trie[cur][c] ;
}
qtd[cur] ++ ;
if(s[l][r-1])
qtdTam[r-l] = max(qtdTam[r-l] , qtd[cur] ) ;
}
void findPalindrome()
{
lp(i,0,n) s[i][i] = true ;
lp(i,0,n-1)
if( str[i] == str[i+1] ) s[i][i+1] = true ;
lp(i,2,n)
for(int j = 0 ; j + i < n ; j++ )
s[j][j+i] = ( s[j+1][j+i-1] && (str[j]==str[j+i]) ) ;
}
int main()
{
scanf(" %s", str ) ;
n = strlen(str) ;
findPalindrome() ;
lp(i,0,n)
lp(j,i, n) add(str,i,j+1) ;
ll ans = 0 ;
lp(i,1,n+1) ans = max(ans, qtdTam[i]*i) ;
printf("%lld\n" , ans );
}
Compilation message (stderr)
palindrome.cpp: In function 'int main()':
palindrome.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", str ) ;
~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |