답안 #635790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635790 2022-08-27T00:36:36 Z chonka 회문 (APIO14_palindrome) C++17
100 / 100
35 ms 46684 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 4e5 + 7 ;

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 ;
        }
    }
};
node v[ MAXN ] ;


void solve ( ) {
    cin >> a ;
    n = a.size ( ) ;
    v[ 0 ].len = -1 ;
    int tp = 1 ;
    
    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[ wh ].to[ ( a[ i ] - 'a' ) ] = ++ tp ;
            v[ tp ].len = v[ wh ].len + 2 ;
            if ( v[ tp ].len > 1 ) { 
                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[ tp ].suff = v[ dummy ].to[ ( a[ i ] - 'a' ) ] ;
            }
            else {
                v[ tp ].suff = 1 ;
            }
        }
        wh = v[ wh ].to[ ( a[ i ] - 'a' ) ] ;        
        ++ v[ wh ].cnt ;
    }
    ll ans = 0 ;
    for ( int i = tp ; 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 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45624 KB Output is correct
2 Correct 21 ms 45724 KB Output is correct
3 Correct 21 ms 45604 KB Output is correct
4 Correct 25 ms 45712 KB Output is correct
5 Correct 26 ms 45692 KB Output is correct
6 Correct 22 ms 45644 KB Output is correct
7 Correct 26 ms 45656 KB Output is correct
8 Correct 26 ms 45668 KB Output is correct
9 Correct 22 ms 45712 KB Output is correct
10 Correct 23 ms 45652 KB Output is correct
11 Correct 21 ms 45652 KB Output is correct
12 Correct 21 ms 45652 KB Output is correct
13 Correct 22 ms 45652 KB Output is correct
14 Correct 20 ms 45732 KB Output is correct
15 Correct 23 ms 45804 KB Output is correct
16 Correct 23 ms 45616 KB Output is correct
17 Correct 26 ms 45652 KB Output is correct
18 Correct 22 ms 45616 KB Output is correct
19 Correct 23 ms 45632 KB Output is correct
20 Correct 22 ms 45712 KB Output is correct
21 Correct 24 ms 45712 KB Output is correct
22 Correct 24 ms 45652 KB Output is correct
23 Correct 23 ms 45712 KB Output is correct
24 Correct 22 ms 45632 KB Output is correct
25 Correct 22 ms 45692 KB Output is correct
26 Correct 22 ms 45652 KB Output is correct
27 Correct 27 ms 45652 KB Output is correct
28 Correct 23 ms 45708 KB Output is correct
29 Correct 25 ms 45628 KB Output is correct
30 Correct 22 ms 45608 KB Output is correct
31 Correct 23 ms 45640 KB Output is correct
32 Correct 25 ms 45728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45620 KB Output is correct
2 Correct 24 ms 45652 KB Output is correct
3 Correct 22 ms 45716 KB Output is correct
4 Correct 24 ms 45608 KB Output is correct
5 Correct 23 ms 45652 KB Output is correct
6 Correct 23 ms 45672 KB Output is correct
7 Correct 22 ms 45652 KB Output is correct
8 Correct 24 ms 45636 KB Output is correct
9 Correct 25 ms 45676 KB Output is correct
10 Correct 22 ms 45680 KB Output is correct
11 Correct 22 ms 45652 KB Output is correct
12 Correct 26 ms 45712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 45648 KB Output is correct
2 Correct 26 ms 45644 KB Output is correct
3 Correct 22 ms 45732 KB Output is correct
4 Correct 23 ms 45708 KB Output is correct
5 Correct 23 ms 45640 KB Output is correct
6 Correct 22 ms 45768 KB Output is correct
7 Correct 24 ms 45680 KB Output is correct
8 Correct 22 ms 45636 KB Output is correct
9 Correct 22 ms 45728 KB Output is correct
10 Correct 22 ms 45712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 45900 KB Output is correct
2 Correct 30 ms 45988 KB Output is correct
3 Correct 26 ms 45932 KB Output is correct
4 Correct 24 ms 45916 KB Output is correct
5 Correct 25 ms 46028 KB Output is correct
6 Correct 26 ms 45936 KB Output is correct
7 Correct 25 ms 46036 KB Output is correct
8 Correct 25 ms 46020 KB Output is correct
9 Correct 24 ms 46036 KB Output is correct
10 Correct 25 ms 46024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 46300 KB Output is correct
2 Correct 33 ms 46616 KB Output is correct
3 Correct 33 ms 46652 KB Output is correct
4 Correct 33 ms 46604 KB Output is correct
5 Correct 35 ms 46588 KB Output is correct
6 Correct 33 ms 46628 KB Output is correct
7 Correct 31 ms 46640 KB Output is correct
8 Correct 27 ms 46636 KB Output is correct
9 Correct 27 ms 46556 KB Output is correct
10 Correct 30 ms 46684 KB Output is correct
11 Correct 30 ms 46548 KB Output is correct
12 Correct 30 ms 46608 KB Output is correct