답안 #654802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654802 2022-11-01T16:33:10 Z NeroZein 회문 (APIO14_palindrome) C++14
100 / 100
26 ms 35208 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+10; 
string s;
int num,suff; 
struct node{
    int next[26];
    int len,num,sufflink;
}tree[N]; 

inline void ini(){
    num = suff = 2; 
    tree[1].len = -1;tree[1].sufflink = 1; 
    tree[2].len =  0;tree[2].sufflink = 1; 
}

inline void add(int pos){
    int cur = suff, curlen = 0; 
    int let = s[pos]-'a'; 
    while (true){
        curlen = tree[cur].len;
        if (pos-1-curlen >= 0 && s[pos-1-curlen] == s[pos])
            break; 
        cur = tree[cur].sufflink;
    }
    if (tree[cur].next[let]){
        suff = tree[cur].next[let]; 
        tree[tree[cur].next[let]].num++; 
        return; 
    }
    suff = ++num;
    tree[cur].next[let] = num;
    tree[num].len = tree[cur].len+2; 
    tree[tree[cur].next[let]].num++; 
    if (tree[num].len == 1){
        tree[num].sufflink = 2; 
        return; 
    }
    while(true){
        cur = tree[cur].sufflink;
        curlen = tree[cur].len; 
        if (pos-1-curlen >= 0 && s[pos-1-curlen] == s[pos]){
            tree[num].sufflink = tree[cur].next[let]; 
            break; 
        }
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin>>s;int n = s.size(); 
    ini(); 
    for(int i=0;i<n;++i)
        add(i); 
    for(int i=n+3;~i;--i)
        tree[tree[i].sufflink].num += tree[i].num;
    long long ans = 0; 
    for(int i=3;i<n+3;i++)
        ans = max(ans, 1LL*tree[i].num*tree[i].len);
    cout<<ans; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11860 KB Output is correct
2 Correct 7 ms 11816 KB Output is correct
3 Correct 8 ms 11860 KB Output is correct
4 Correct 8 ms 11860 KB Output is correct
5 Correct 10 ms 11784 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 7 ms 10068 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 3156 KB Output is correct
10 Correct 7 ms 10068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 34704 KB Output is correct
2 Correct 23 ms 35040 KB Output is correct
3 Correct 23 ms 35208 KB Output is correct
4 Correct 26 ms 35064 KB Output is correct
5 Correct 25 ms 35036 KB Output is correct
6 Correct 23 ms 31172 KB Output is correct
7 Correct 25 ms 29276 KB Output is correct
8 Correct 11 ms 1252 KB Output is correct
9 Correct 11 ms 1244 KB Output is correct
10 Correct 22 ms 28892 KB Output is correct
11 Correct 24 ms 35032 KB Output is correct
12 Correct 12 ms 4336 KB Output is correct