Submission #868894

# Submission time Handle Problem Language Result Execution time Memory
868894 2023-11-02T12:00:54 Z sleepntsheep Palindromes (APIO14_palindrome) C++17
100 / 100
18 ms 34908 KB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 300005

char s[N]; 
int lz[N], len[N], link[N], nxt[N][26], n = 2, t = 2;
ll ans;

void init()
{
    n = t = 2;
    len[1] = -1, link[1] = 1;
    len[2] = 0, link[2] = 1;
}

void append(int pos)
{
    int la, l, c = s[pos] - 'a';
    for (l = t; !(pos-1>=len[l] && s[pos-1-len[l]] == s[pos]); l = link[l]);
    if (nxt[l][c]) { ++lz[t = nxt[l][c]]; return; }

    t = ++n;
    len[n] = len[l] + 2;
    ++lz[n];
    nxt[l][c] = n;

    if (len[n] == 1)
    {
        link[n] = 2;
        return;
    }

    for (la = link[l]; !(pos-1>=len[la] && s[pos-1-len[la]] == s[pos]); la=link[la]);
    link[n] = nxt[la][c];
}

void pushlazy()
{
    for (int i = n; i >= 3; --i)
    {
        lz[link[i]] += lz[i];
        ans = max(ans, 1ll*lz[i]*len[i]);
    }
}


int main()
{
    ShinLena;
    cin >> s;
    init();
    for (int i = 0; s[i]; ++i) append(i);
    pushlazy();
    cout << ans;
    return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4564 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4696 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4568 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5468 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5468 KB Output is correct
4 Correct 1 ms 5468 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 1 ms 5464 KB Output is correct
7 Correct 1 ms 5468 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 15064 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 6 ms 14944 KB Output is correct
5 Correct 5 ms 14900 KB Output is correct
6 Correct 5 ms 12128 KB Output is correct
7 Correct 5 ms 13408 KB Output is correct
8 Correct 2 ms 4704 KB Output is correct
9 Correct 3 ms 6988 KB Output is correct
10 Correct 6 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 34652 KB Output is correct
2 Correct 15 ms 34592 KB Output is correct
3 Correct 15 ms 34652 KB Output is correct
4 Correct 18 ms 34816 KB Output is correct
5 Correct 18 ms 34648 KB Output is correct
6 Correct 14 ms 32828 KB Output is correct
7 Correct 14 ms 31068 KB Output is correct
8 Correct 4 ms 4956 KB Output is correct
9 Correct 5 ms 5212 KB Output is correct
10 Correct 15 ms 30832 KB Output is correct
11 Correct 15 ms 34908 KB Output is correct
12 Correct 6 ms 7972 KB Output is correct