Submission #635789

#TimeUsernameProblemLanguageResultExecution timeMemory
635789chonkaPalindromes (APIO14_palindrome)C++17
0 / 100
35 ms30480 KiB
#include<bits/stdc++.h> using namespace std ; typedef long long ll ; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n ; string a ; struct node { int len , cnt ; int to[ 26 ] ; int suff ; node ( ) { len = cnt = suff = 0 ; for ( int i = 0 ; i < 26 ; ++ i ) { to[ i ] = 0 ; } } }; vector < node > v ; void solve ( ) { cin >> a ; n = a.size ( ) ; v.push_back ( node ( ) ) ; v[ 0 ].len = -1 ; v.push_back ( node ( ) ) ; int wh = 0 ; for ( int i = 0 ; i < n ; ++ i ) { while ( wh > 0 && ( i - v[ wh ].len - 1 < 0 || a[ i - v[ wh ].len - 1 ] != a[ i ] ) ) { wh = v[ wh ].suff ; } if ( v[ wh ].to[ ( a[ i ] - 'a' ) ] == 0 ) { v.push_back ( node ( ) ) ; v[ wh ].to[ ( a[ i ] - 'a' ) ] = (int)v.size ( ) - 1 ; v.back ( ).len = v[ wh ].len + 2 ; int dummy = v[ wh ].suff ; while ( dummy > 0 && ( i - v[ dummy ].len - 1 < 0 || a[ i - v[ dummy ].len - 1 ] != a[ i ] ) ) { dummy = v[ dummy ].suff ; } v[ wh ].suff = v[ dummy ].to[ ( a[ i ] - 'a' ) ] ; } wh = v[ wh ].to[ ( a[ i ] - 'a' ) ] ; ++ v[ wh ].cnt ; } ll ans = 0 ; int sz = v.size ( ) ; for ( int i = sz - 1 ; i >= 0 ; -- i ) { v[ v[ i ].suff ].cnt += v[ i ].cnt ; ans = max ( ans , 1LL * v[ i ].len * v[ i ].cnt ) ; } cout << ans << "\n" ; } int main ( ) { ios_base :: sync_with_stdio ( false ) ; cin.tie ( NULL ) ; int t = 1 ; // cin >> t ; while ( t -- ) { solve ( ) ; } 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...