답안 #1062523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062523 2024-08-17T08:14:45 Z MladenP 회문 (APIO14_palindrome) C++17
100 / 100
40 ms 64060 KB
#include <iostream>
#include <vector>
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
using namespace std;

const int P_SIGMA = 26;
const int MINUS_NODE = 1;
const int ZERO_NODE = 2;

struct Node {
    int len, slink, cnt, dub;
    int to[P_SIGMA];
    Node(int _len = 0, int _slink = 0, int _cnt = 0, int _depth = 0) {
        len = _len; slink = _slink; cnt = _cnt; dub = _depth;
        for(int i = 0; i < P_SIGMA; i++) to[i] = 0;
    }
};

string s;
vector<Node> pt;
int suff;

void init() {
    suff = 2;
    s = "";
    pt.push_back(Node(0));
    pt.push_back(Node(-1, MINUS_NODE));
    pt.push_back(Node(0, MINUS_NODE));
}

int addLetter(char c) {
    s += c; 
    int cidx = c-'a';
    int len = s.size();
    while(c != s[len-2-pt[suff].len]) {
        suff = pt[suff].slink;
    }
    int nd = pt[suff].to[cidx];

    if(nd == 0) {
        nd = pt.size();
        pt[suff].to[cidx] = nd;
        pt.push_back(Node(pt[suff].len+2));
        if(suff == MINUS_NODE) {
            pt[nd].slink = ZERO_NODE;
        } else {
            int u = pt[suff].slink;
            while(c != s[len-2-pt[u].len]) {
                u = pt[u].slink;
            }
            pt[nd].slink = pt[u].to[cidx];
        }
        pt[nd].dub = pt[pt[nd].slink].dub+1;
    }
    pt[nd].cnt++;
    suff = nd;
    return pt[nd].dub;
}

void calcCnt() {
    for(int i = pt.size()-1; i > 2; i--) {
        pt[pt[i].slink].cnt += pt[i].cnt;
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s;
    init();
    for(auto x : s) {
        addLetter(x);
    }
    calcCnt();
    long long rez = 0;
    for(int i = pt.size()-1; i > 2; i--) {
        rez = max(rez, (long long) pt[i].len*pt[i].cnt);
    }
    cout << rez << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2332 KB Output is correct
2 Correct 1 ms 2336 KB Output is correct
3 Correct 2 ms 2584 KB Output is correct
4 Correct 2 ms 2328 KB Output is correct
5 Correct 2 ms 2332 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 2 ms 2376 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16436 KB Output is correct
2 Correct 8 ms 17180 KB Output is correct
3 Correct 8 ms 17976 KB Output is correct
4 Correct 9 ms 17208 KB Output is correct
5 Correct 8 ms 17720 KB Output is correct
6 Correct 8 ms 17464 KB Output is correct
7 Correct 8 ms 16696 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 4 ms 5824 KB Output is correct
10 Correct 8 ms 17664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 64060 KB Output is correct
2 Correct 38 ms 63292 KB Output is correct
3 Correct 35 ms 63824 KB Output is correct
4 Correct 35 ms 63296 KB Output is correct
5 Correct 34 ms 63168 KB Output is correct
6 Correct 37 ms 63276 KB Output is correct
7 Correct 21 ms 32596 KB Output is correct
8 Correct 6 ms 1764 KB Output is correct
9 Correct 6 ms 1764 KB Output is correct
10 Correct 19 ms 32912 KB Output is correct
11 Correct 36 ms 63316 KB Output is correct
12 Correct 8 ms 5420 KB Output is correct