답안 #692520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
692520 2023-02-01T17:37:43 Z PoonYaPat 회문 (APIO14_palindrome) C++14
100 / 100
32 ms 38588 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node {
    ll lenght,cnt;
    int ins[26],suffix;
} tree[300001];

string s;
int cur_node=1,c=2;

void add(int idx) {

    int temp=cur_node;
    while (true) {
        int len=tree[temp].lenght;
        if (idx-len>=1 && s[idx]==s[idx-len-1]) break;
        temp=tree[temp].suffix;
    }

    if (tree[temp].ins[s[idx]-'a']!=0) { //already have
        cur_node=tree[temp].ins[s[idx]-'a'];
        tree[cur_node].cnt=tree[cur_node].cnt+1;
        return;
    }

    tree[temp].ins[s[idx]-'a']=++c;
    tree[c].lenght=tree[temp].lenght+2;
    tree[c].cnt=1;

    cur_node=c;

    if (tree[cur_node].lenght==1) {
        tree[cur_node].suffix=2;
        return;
    }

    temp=tree[temp].suffix;

    while (true) {
        int len=tree[temp].lenght;
        if (idx-len>=1 && s[idx]==s[idx-len-1]) break;
        temp=tree[temp].suffix;
    }

    tree[cur_node].suffix=tree[temp].ins[s[idx]-'a'];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>s;

    tree[1].lenght=-1;
    tree[1].suffix=1;
    tree[2].lenght=0;
    tree[2].suffix=1;

    for (int i=0; i<s.size(); ++i) add(i);
    for (int i=c; i>=3; --i) tree[tree[i].suffix].cnt=tree[tree[i].suffix].cnt+tree[i].cnt;

    ll mmax=0;
    for (int i=3; i<=c; ++i) mmax=max(mmax,tree[i].cnt*tree[i].lenght);
    cout<<mmax;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i=0; i<s.size(); ++i) add(i);
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 392 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 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 1616 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 9 ms 13012 KB Output is correct
2 Correct 8 ms 13012 KB Output is correct
3 Correct 8 ms 13016 KB Output is correct
4 Correct 9 ms 13144 KB Output is correct
5 Correct 8 ms 13164 KB Output is correct
6 Correct 8 ms 9688 KB Output is correct
7 Correct 9 ms 11128 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 3536 KB Output is correct
10 Correct 9 ms 11220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 38308 KB Output is correct
2 Correct 27 ms 38276 KB Output is correct
3 Correct 23 ms 38280 KB Output is correct
4 Correct 30 ms 38552 KB Output is correct
5 Correct 32 ms 38588 KB Output is correct
6 Correct 28 ms 34328 KB Output is correct
7 Correct 22 ms 32224 KB Output is correct
8 Correct 6 ms 1248 KB Output is correct
9 Correct 6 ms 1244 KB Output is correct
10 Correct 24 ms 31696 KB Output is correct
11 Correct 24 ms 38580 KB Output is correct
12 Correct 7 ms 4568 KB Output is correct