Submission #89872

# Submission time Handle Problem Language Result Execution time Memory
89872 2018-12-18T17:15:09 Z Alexa2001 Palindromes (APIO14_palindrome) C++17
100 / 100
106 ms 81404 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Nmax = 1e6 + 5;

struct tr
{
    int len, sufflink, cnt;
    map<char, int> go;
};
string S;

class PalindromicTree
{
    int nodes, suff;
    tr a[Nmax];

public:
    void init()
    {
        nodes = 2;
        a[1].len = -1;
        a[1].sufflink = 1;
        a[1].cnt = 0;
        a[2].len = 0;
        a[2].sufflink = 1;
        a[2].cnt = 0;
        suff = 2;
    }

    void add(char c, int pos)
    {
        int act = a[suff].len, node = suff;

        while(pos-act-1<0 || S[pos] != S[pos - act - 1])
        {
            node = a[node].sufflink;
            act = a[node].len;
        }

        if(a[node].go[c])
        {
            suff = a[node].go[c];
            ++a[suff].cnt;
            return;
        }

        a[node].go[c] = ++nodes;
        a[nodes].len = a[node].len + 2;
        a[nodes].cnt = 1;
        suff = nodes;

        if(a[nodes].len == 1)
        {
            a[nodes].sufflink = 2;
            return;
        }

        node = a[node].sufflink;
        act = a[node].len;

        while(pos-act-1<0 || S[pos] != S[pos - act - 1])
        {
            node = a[node].sufflink;
            act = a[node].len;
        }

        a[nodes].sufflink = a[node].go[c];
    }

    ll get_result()
    {
        int i;
        ll ans = 0;
        for(i=nodes; i; --i)
            a[a[i].sufflink].cnt += a[i].cnt;
        for(i=3; i<=nodes; ++i)
            ans = max(ans, (ll) a[i].cnt * a[i].len);
        return ans;
    }

} paltree;

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    paltree.init();

    cin >> S;
    int nr = 0;
    for(auto letter : S)
        paltree.add(letter, nr++);

    cout << paltree.get_result() << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 64 ms 63012 KB Output is correct
2 Correct 61 ms 63112 KB Output is correct
3 Correct 65 ms 63140 KB Output is correct
4 Correct 60 ms 63140 KB Output is correct
5 Correct 67 ms 63140 KB Output is correct
6 Correct 66 ms 63140 KB Output is correct
7 Correct 61 ms 63140 KB Output is correct
8 Correct 61 ms 63140 KB Output is correct
9 Correct 63 ms 63140 KB Output is correct
10 Correct 66 ms 63252 KB Output is correct
11 Correct 64 ms 63252 KB Output is correct
12 Correct 64 ms 63252 KB Output is correct
13 Correct 69 ms 63396 KB Output is correct
14 Correct 61 ms 63396 KB Output is correct
15 Correct 63 ms 63396 KB Output is correct
16 Correct 61 ms 63396 KB Output is correct
17 Correct 68 ms 63396 KB Output is correct
18 Correct 64 ms 63396 KB Output is correct
19 Correct 67 ms 63396 KB Output is correct
20 Correct 62 ms 63396 KB Output is correct
21 Correct 61 ms 63396 KB Output is correct
22 Correct 63 ms 63396 KB Output is correct
23 Correct 67 ms 63396 KB Output is correct
24 Correct 65 ms 63396 KB Output is correct
25 Correct 68 ms 63396 KB Output is correct
26 Correct 63 ms 63396 KB Output is correct
27 Correct 62 ms 63396 KB Output is correct
28 Correct 64 ms 63396 KB Output is correct
29 Correct 53 ms 63396 KB Output is correct
30 Correct 64 ms 63396 KB Output is correct
31 Correct 54 ms 63396 KB Output is correct
32 Correct 66 ms 63396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 63396 KB Output is correct
2 Correct 62 ms 63396 KB Output is correct
3 Correct 60 ms 63396 KB Output is correct
4 Correct 70 ms 63396 KB Output is correct
5 Correct 68 ms 63396 KB Output is correct
6 Correct 69 ms 63396 KB Output is correct
7 Correct 63 ms 63396 KB Output is correct
8 Correct 54 ms 63396 KB Output is correct
9 Correct 53 ms 63396 KB Output is correct
10 Correct 54 ms 63396 KB Output is correct
11 Correct 37 ms 63396 KB Output is correct
12 Correct 56 ms 63396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 63740 KB Output is correct
2 Correct 59 ms 63764 KB Output is correct
3 Correct 55 ms 63764 KB Output is correct
4 Correct 54 ms 63764 KB Output is correct
5 Correct 55 ms 63764 KB Output is correct
6 Correct 65 ms 63764 KB Output is correct
7 Correct 72 ms 63764 KB Output is correct
8 Correct 64 ms 63764 KB Output is correct
9 Correct 65 ms 63764 KB Output is correct
10 Correct 61 ms 63764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 67964 KB Output is correct
2 Correct 79 ms 68092 KB Output is correct
3 Correct 82 ms 68092 KB Output is correct
4 Correct 81 ms 68220 KB Output is correct
5 Correct 79 ms 68292 KB Output is correct
6 Correct 76 ms 68292 KB Output is correct
7 Correct 75 ms 68292 KB Output is correct
8 Correct 70 ms 68292 KB Output is correct
9 Correct 71 ms 68292 KB Output is correct
10 Correct 77 ms 68292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 78480 KB Output is correct
2 Correct 94 ms 78764 KB Output is correct
3 Correct 89 ms 79064 KB Output is correct
4 Correct 92 ms 79360 KB Output is correct
5 Correct 94 ms 79652 KB Output is correct
6 Correct 93 ms 79652 KB Output is correct
7 Correct 86 ms 79652 KB Output is correct
8 Correct 82 ms 79652 KB Output is correct
9 Correct 80 ms 79652 KB Output is correct
10 Correct 83 ms 79652 KB Output is correct
11 Correct 106 ms 81404 KB Output is correct
12 Correct 87 ms 81404 KB Output is correct