답안 #251373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251373 2020-07-21T04:26:40 Z phuleethanh 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 5108 KB
#include <bits/stdc++.h>
using namespace std;
struct nut
{
    int len = 0, num = 0, suffLink = 0, child[26] = {0}, nlen = 0;
};
int curNode;
vector<nut> Tree;
string s;

void initPalinTree()
{
    Tree.emplace_back();
    Tree[0].len = 0, Tree[0].suffLink = 1;
    Tree.emplace_back();
    Tree[1].len = -1, Tree[1].suffLink = 1;
    curNode = 0;
}

bool insert(int i)
{
    int w = s[i] - 'a';
    int x = curNode;
    while (1)
    {
        int k = Tree[x].len;
        if (i - k - 1 >= 0 && s[i - k - 1] == s[i])
            break;
        x = Tree[x].suffLink;
    }
    if (Tree[x].child[w])
        return curNode = Tree[x].child[w], 0;
    curNode = Tree.size();
    Tree.emplace_back();
    Tree[x].child[w] = curNode;
    Tree[curNode].len = Tree[x].len + 2;
    Tree[curNode].nlen = 1;
    Tree[curNode].num = 1;
    if (Tree[curNode].len == 1)
        return Tree[curNode].suffLink = 0, 1;
    while (1)
    {
        x = Tree[x].suffLink;
        int k = Tree[x].len;
        if (i - k - 1 >= 0 && s[i - k - 1] == s[i])
            break;
    }
    Tree[curNode].suffLink = Tree[x].child[w];
    Tree[curNode].num = Tree[Tree[curNode].suffLink].num + 1;
    return 1;
}

void capnhatnguoc(int x)
{
    while (x > 1) //Khi nao con khac hai nut goc
    {
        x = Tree[x].suffLink; //di nguoc len nut suffLink
        if (x > 1)
            Tree[x].nlen++;
    }
}

int main()
{
    //freopen("z.inp", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    initPalinTree();
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        insert(i);
        capnhatnguoc(curNode);
    }
    long long ans = 1;
    for (auto x : Tree)
        ans = max(ans, 1ll * x.len * x.nlen);
    cout << ans;
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:69:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++)
                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 2484 KB Output is correct
2 Correct 78 ms 2488 KB Output is correct
3 Correct 223 ms 2360 KB Output is correct
4 Correct 168 ms 2488 KB Output is correct
5 Correct 3 ms 2496 KB Output is correct
6 Correct 7 ms 2496 KB Output is correct
7 Correct 27 ms 2488 KB Output is correct
8 Incorrect 1 ms 512 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 4724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 5108 KB Time limit exceeded
2 Halted 0 ms 0 KB -