답안 #109982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109982 2019-05-08T14:02:15 Z PeppaPig 회문 (APIO14_palindrome) C++14
100 / 100
56 ms 34936 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 3e5+5;

int n;
int t[N][26], len[N], link[N], occ[N], idx, suff;
char S[N];

void add(int pos) {
    int cur = suff, x = S[pos] - 'a';
    while(pos - 1 - len[cur] < 0 || S[pos - 1 - len[cur]] != S[pos])
        cur = link[cur];
    if(t[cur][x]) {
        suff = t[cur][x];
        ++occ[t[cur][x]];
        return;
    }
    suff = ++idx;
    len[idx] = len[cur] + 2, t[cur][x] = idx, occ[idx] = 1;
    if(len[idx] == 1) { link[idx] = 2; return; }
    cur = link[cur];
    while(pos - 1 - len[cur] < 0 || S[pos - 1 - len[cur]] != S[pos])
        cur = link[cur];
    link[idx] = t[cur][x];
}

void init_tree() {
    idx = suff = 2;
    len[1] = -1, len[2] = 0;
    link[1] = 1, link[2] = 1;
}

int main() {
    scanf("%s", S+1); n = strlen(S+1);
    init_tree();
    for(int i = 1; i <= n; i++) add(i);
    long ans = 0;
    for(int i = idx; i > 2; i--) {
        occ[link[i]] += occ[i];
        ans = max(ans, 1ll * len[i] * occ[i]);
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", S+1); n = strlen(S+1);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 4 ms 1408 KB Output is correct
3 Correct 4 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 4 ms 1408 KB Output is correct
6 Correct 4 ms 1536 KB Output is correct
7 Correct 4 ms 1536 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 11904 KB Output is correct
2 Correct 15 ms 11904 KB Output is correct
3 Correct 16 ms 11904 KB Output is correct
4 Correct 15 ms 12032 KB Output is correct
5 Correct 22 ms 11904 KB Output is correct
6 Correct 13 ms 8832 KB Output is correct
7 Correct 20 ms 10104 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 6 ms 3200 KB Output is correct
10 Correct 15 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 34936 KB Output is correct
2 Correct 45 ms 34936 KB Output is correct
3 Correct 41 ms 34936 KB Output is correct
4 Correct 40 ms 34936 KB Output is correct
5 Correct 56 ms 34936 KB Output is correct
6 Correct 42 ms 31100 KB Output is correct
7 Correct 37 ms 29184 KB Output is correct
8 Correct 7 ms 1024 KB Output is correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 51 ms 28920 KB Output is correct
11 Correct 39 ms 34936 KB Output is correct
12 Correct 12 ms 4224 KB Output is correct