Submission #1085050

# Submission time Handle Problem Language Result Execution time Memory
1085050 2024-09-07T12:30:33 Z Aliyyiakbar Palindromes (APIO14_palindrome) C++17
100 / 100
36 ms 69600 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>

#define int long long
#define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int sz = 3e5+9;
const int LOG = 65;
const int MOD = 1e9+7;
const int INF = 1e18;

struct PT
{
    struct Node
    {
        int next[26], link, len;
        int occ;
    };
    string s;
    vector<Node> t;
    int siz, last, n;
    int res;
    PT(string& _s) : s(_s), n(_s.size()), res(0)
    {
        t.resize(n + 3);
        t[0].len = -1;
        t[1].len = 0;
        t[0].link = t[1].link = 0;
        siz = 2, last = 1;
        for (int i = 0; i <= n; ++i)
        {
            for (int j = 0; j < 26; ++j)
            {
                t[i].next[j] = -1;
            }
        }
    }
    void extend(int i)
    {
        int cur = last, cur_len = 0, letter = s[i] - 'a';
        while (true)
        {
            cur_len = t[cur].len;
            if (i - cur_len - 1 >= 0 && s[i] == s[i - cur_len - 1])
            {
                break;
            }
            cur = t[cur].link;
        }
        if (t[cur].next[letter] != -1)
        {
            last = t[cur].next[letter];
            t[last].occ++;
            return;
        }
        last = siz++;
        t[last].len = t[cur].len + 2;
        t[last].occ = 1;
        t[cur].next[letter] = last;
        if (t[last].len == 1)
        {
            t[last].link = 1;
        }
        else
        {
            while (true)
            {
                cur = t[cur].link;
                cur_len = t[cur].len;
                if (i - cur_len - 1 >= 0 && s[i] == s[i - cur_len - 1])
                {
                    t[last].link = t[cur].next[letter];
                    break;
                }
            }
        }
    }
    void build()
    {
        for (int i = siz - 1; i >= 2; --i)
        {
            t[t[i].link].occ += t[i].occ;
        }
    }
    void calllc()
    {
        for (int i = 2; i < siz; ++i)
        {
            res = max(res,t[i].len*t[i].occ);
        }
    }
};

string s;

void solve()
{
    cin>>s;
    PT pt(s);
    for (int i = 0; i < (int)s.length(); ++i)
    {
        pt.extend(i);
    }
    pt.build();
    pt.calllc();
    cout<<pt.res<<'\n';
}

signed main()
{
    $AzH_TxdmN$
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 456 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2764 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 23248 KB Output is correct
2 Correct 7 ms 23388 KB Output is correct
3 Correct 7 ms 23464 KB Output is correct
4 Correct 7 ms 23384 KB Output is correct
5 Correct 9 ms 23388 KB Output is correct
6 Correct 7 ms 23388 KB Output is correct
7 Correct 7 ms 23388 KB Output is correct
8 Correct 6 ms 23244 KB Output is correct
9 Correct 7 ms 23384 KB Output is correct
10 Correct 6 ms 23388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 69512 KB Output is correct
2 Correct 36 ms 69344 KB Output is correct
3 Correct 33 ms 69460 KB Output is correct
4 Correct 36 ms 69348 KB Output is correct
5 Correct 34 ms 69348 KB Output is correct
6 Correct 33 ms 69344 KB Output is correct
7 Correct 34 ms 69576 KB Output is correct
8 Correct 30 ms 69436 KB Output is correct
9 Correct 30 ms 69336 KB Output is correct
10 Correct 36 ms 69352 KB Output is correct
11 Correct 36 ms 69336 KB Output is correct
12 Correct 35 ms 69600 KB Output is correct