Submission #251413

# Submission time Handle Problem Language Result Execution time Memory
251413 2020-07-21T07:26:52 Z phuleethanh Palindromes (APIO14_palindrome) C++14
100 / 100
28 ms 35464 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 303030;
struct nut
{
    int len = 0, occ = 0, suffLink = 0, child[26];
} Tree[N];
string s;
int last, num;

void insert(int i)
{
    //Tim nut X to nhat thoa man
    while (i - Tree[last].len - 1 < 0 || s[i - Tree[last].len - 1] != s[i])
        last = Tree[last].suffLink;
    int w = s[i] - 'a';
    //Them moi : Neu nut nay chua co trong cay
    if (Tree[last].child[w] == 0)
    {
        //tim nut suffixLink tro toi
        int tmp = Tree[last].suffLink;
        while (i - Tree[tmp].len - 1 < 0 || s[i - Tree[tmp].len - 1] != s[i])
            tmp = Tree[tmp].suffLink;
        //tao nut moi va tro vao day
        Tree[last].child[w] = ++num, Tree[num].len = Tree[last].len + 2;
        Tree[num].suffLink = (Tree[num].len == 1 ? 0 : Tree[tmp].child[w]);
    }
    last = Tree[last].child[w];
    Tree[last].occ++;
}

int main()
{
    //freopen("z.inp", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    Tree[1].len = -1, Tree[0].suffLink = Tree[1].suffLink = 1;
    last = 0, num = 1;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        insert(i);
    long long ans = 0;
    for (int i = num; i >= 2; i--)
    {
        ans = max(ans, 1ll * Tree[i].len * Tree[i].occ);
        Tree[Tree[i].suffLink].occ += Tree[i].occ;
    }
    cout << ans;
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++)
                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 34816 KB Output is correct
2 Correct 15 ms 34688 KB Output is correct
3 Correct 17 ms 34816 KB Output is correct
4 Correct 15 ms 34688 KB Output is correct
5 Correct 17 ms 34816 KB Output is correct
6 Correct 15 ms 34688 KB Output is correct
7 Correct 15 ms 34688 KB Output is correct
8 Correct 15 ms 34688 KB Output is correct
9 Correct 15 ms 34688 KB Output is correct
10 Correct 15 ms 34688 KB Output is correct
11 Correct 15 ms 34680 KB Output is correct
12 Correct 16 ms 34688 KB Output is correct
13 Correct 15 ms 34688 KB Output is correct
14 Correct 15 ms 34688 KB Output is correct
15 Correct 15 ms 34688 KB Output is correct
16 Correct 15 ms 34688 KB Output is correct
17 Correct 18 ms 34688 KB Output is correct
18 Correct 15 ms 34688 KB Output is correct
19 Correct 15 ms 34688 KB Output is correct
20 Correct 15 ms 34688 KB Output is correct
21 Correct 18 ms 34688 KB Output is correct
22 Correct 16 ms 34736 KB Output is correct
23 Correct 18 ms 34688 KB Output is correct
24 Correct 15 ms 34688 KB Output is correct
25 Correct 17 ms 34688 KB Output is correct
26 Correct 15 ms 34688 KB Output is correct
27 Correct 18 ms 34688 KB Output is correct
28 Correct 18 ms 34688 KB Output is correct
29 Correct 15 ms 34688 KB Output is correct
30 Correct 15 ms 34688 KB Output is correct
31 Correct 17 ms 34688 KB Output is correct
32 Correct 17 ms 34688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 34688 KB Output is correct
2 Correct 18 ms 34688 KB Output is correct
3 Correct 16 ms 34688 KB Output is correct
4 Correct 18 ms 34752 KB Output is correct
5 Correct 15 ms 34688 KB Output is correct
6 Correct 18 ms 34688 KB Output is correct
7 Correct 16 ms 34688 KB Output is correct
8 Correct 18 ms 34688 KB Output is correct
9 Correct 15 ms 34688 KB Output is correct
10 Correct 18 ms 34688 KB Output is correct
11 Correct 17 ms 34688 KB Output is correct
12 Correct 16 ms 34688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 34688 KB Output is correct
2 Correct 17 ms 34700 KB Output is correct
3 Correct 16 ms 34816 KB Output is correct
4 Correct 16 ms 34688 KB Output is correct
5 Correct 16 ms 34688 KB Output is correct
6 Correct 15 ms 34688 KB Output is correct
7 Correct 16 ms 34688 KB Output is correct
8 Correct 15 ms 34688 KB Output is correct
9 Correct 15 ms 34688 KB Output is correct
10 Correct 17 ms 34688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 34944 KB Output is correct
2 Correct 18 ms 35072 KB Output is correct
3 Correct 18 ms 35072 KB Output is correct
4 Correct 19 ms 35072 KB Output is correct
5 Correct 18 ms 35072 KB Output is correct
6 Correct 18 ms 35072 KB Output is correct
7 Correct 18 ms 35072 KB Output is correct
8 Correct 18 ms 35072 KB Output is correct
9 Correct 18 ms 35072 KB Output is correct
10 Correct 17 ms 35072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 35336 KB Output is correct
2 Correct 27 ms 35456 KB Output is correct
3 Correct 27 ms 35464 KB Output is correct
4 Correct 28 ms 35464 KB Output is correct
5 Correct 25 ms 35464 KB Output is correct
6 Correct 24 ms 35464 KB Output is correct
7 Correct 25 ms 35464 KB Output is correct
8 Correct 23 ms 35456 KB Output is correct
9 Correct 24 ms 35464 KB Output is correct
10 Correct 25 ms 35464 KB Output is correct
11 Correct 24 ms 35464 KB Output is correct
12 Correct 24 ms 35464 KB Output is correct