Submission #46581

# Submission time Handle Problem Language Result Execution time Memory
46581 2018-04-21T14:30:59 Z tieunhi Palindromes (APIO14_palindrome) C++14
100 / 100
57 ms 39860 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 300005
#define maxc 1000000007

using namespace std;

string s;
int sz, cur;

struct PTNode
{
    int first, length, occurance, suffix, child[26];
    PTNode(int first = 0, int length = 0) : first(first), length(length)
    {
        occurance = suffix = 0;
        for (int i = 0; i < 26; i++) child[i] = 0;
    }
}node[N];

void add(int pos)
{
    int start;
    while (1)
    {
        start = pos - node[cur].length - 1;
        if (start >= 0 && s[start] == s[pos])
            break;
        cur = node[cur].suffix;
    }

    int z = s[pos] - 'a';
    if (node[cur].child[z])
    {
        cur = node[cur].child[z];
        node[cur].occurance++;
        return;
    }

    node[++sz] = PTNode(start, node[cur].length + 2);
    node[cur].child[z] = sz;
    if (node[sz].length == 1)
        node[sz].suffix = 2;
    else
    {
        while (1)
        {
            cur = node[cur].suffix;
            int start = pos - node[cur].length - 1;
            if (start >= 0 && s[start] == s[pos])
                break;
        }
        node[sz].suffix = node[cur].child[z];
    }
    node[sz].occurance++;
    cur = sz;
    return;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    sz = cur = 2;
    node[1] = PTNode(0, -1); node[2] = PTNode(0, 0);
    node[1].suffix = node[2].suffix = 1;
    for (int i = 0; i < s.size(); i++)
        add(i);
    long long res = 0;
    for (int i = sz; i >= 3; i--)
    {
        node[node[i].suffix].occurance += node[i].occurance;
        res = max(res, 1ll*node[i].occurance*node[i].length);
    }
    cout <<res;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:70: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 30 ms 35576 KB Output is correct
2 Correct 30 ms 35576 KB Output is correct
3 Correct 29 ms 35616 KB Output is correct
4 Correct 35 ms 35820 KB Output is correct
5 Correct 31 ms 35820 KB Output is correct
6 Correct 31 ms 35820 KB Output is correct
7 Correct 30 ms 35820 KB Output is correct
8 Correct 35 ms 35820 KB Output is correct
9 Correct 30 ms 35940 KB Output is correct
10 Correct 31 ms 35940 KB Output is correct
11 Correct 30 ms 35940 KB Output is correct
12 Correct 32 ms 35940 KB Output is correct
13 Correct 31 ms 35940 KB Output is correct
14 Correct 32 ms 35940 KB Output is correct
15 Correct 31 ms 35940 KB Output is correct
16 Correct 38 ms 35940 KB Output is correct
17 Correct 39 ms 35940 KB Output is correct
18 Correct 40 ms 35940 KB Output is correct
19 Correct 29 ms 35940 KB Output is correct
20 Correct 38 ms 35940 KB Output is correct
21 Correct 30 ms 35940 KB Output is correct
22 Correct 29 ms 35964 KB Output is correct
23 Correct 33 ms 35964 KB Output is correct
24 Correct 39 ms 35964 KB Output is correct
25 Correct 31 ms 35964 KB Output is correct
26 Correct 31 ms 35964 KB Output is correct
27 Correct 30 ms 35964 KB Output is correct
28 Correct 31 ms 35964 KB Output is correct
29 Correct 33 ms 35964 KB Output is correct
30 Correct 29 ms 35964 KB Output is correct
31 Correct 30 ms 35964 KB Output is correct
32 Correct 33 ms 35964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 35964 KB Output is correct
2 Correct 29 ms 35964 KB Output is correct
3 Correct 35 ms 35964 KB Output is correct
4 Correct 32 ms 35964 KB Output is correct
5 Correct 30 ms 35964 KB Output is correct
6 Correct 34 ms 35964 KB Output is correct
7 Correct 30 ms 35964 KB Output is correct
8 Correct 30 ms 35964 KB Output is correct
9 Correct 29 ms 35964 KB Output is correct
10 Correct 30 ms 35964 KB Output is correct
11 Correct 29 ms 35964 KB Output is correct
12 Correct 33 ms 35964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 35964 KB Output is correct
2 Correct 29 ms 35964 KB Output is correct
3 Correct 31 ms 35964 KB Output is correct
4 Correct 29 ms 35964 KB Output is correct
5 Correct 28 ms 35964 KB Output is correct
6 Correct 32 ms 35964 KB Output is correct
7 Correct 30 ms 35964 KB Output is correct
8 Correct 28 ms 35964 KB Output is correct
9 Correct 30 ms 35964 KB Output is correct
10 Correct 33 ms 35964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 36000 KB Output is correct
2 Correct 40 ms 36004 KB Output is correct
3 Correct 36 ms 36004 KB Output is correct
4 Correct 36 ms 36044 KB Output is correct
5 Correct 34 ms 36092 KB Output is correct
6 Correct 36 ms 36092 KB Output is correct
7 Correct 35 ms 36092 KB Output is correct
8 Correct 33 ms 36092 KB Output is correct
9 Correct 33 ms 36092 KB Output is correct
10 Correct 35 ms 36092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 36484 KB Output is correct
2 Correct 51 ms 36864 KB Output is correct
3 Correct 50 ms 37112 KB Output is correct
4 Correct 51 ms 37428 KB Output is correct
5 Correct 53 ms 37740 KB Output is correct
6 Correct 57 ms 38164 KB Output is correct
7 Correct 47 ms 38364 KB Output is correct
8 Correct 45 ms 38664 KB Output is correct
9 Correct 41 ms 39100 KB Output is correct
10 Correct 48 ms 39268 KB Output is correct
11 Correct 50 ms 39648 KB Output is correct
12 Correct 37 ms 39860 KB Output is correct