Submission #843858

# Submission time Handle Problem Language Result Execution time Memory
843858 2023-09-04T16:04:19 Z arnold518 Palindromes (APIO14_palindrome) C++17
100 / 100
38 ms 46036 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3e5;

int N;
string S;

struct Node
{
    int len, link;
    vector<int> chd;
    Node()
    {
        len=0; link=-1;
        chd=vector<int>(26, -1);
    }
};

Node NS[MAXN+10];
int ncnt, P[MAXN+10];

int newNode()
{
    return ncnt++;
}

void EERTREE(int N, string S)
{
    int root1=newNode(), root2=newNode(); // root1 : -1, root2 : 0
    NS[root1].len=-1; NS[root1].link=root1;
    NS[root2].len=0; NS[root2].link=root1;
    int cur=root1;

    for(int i=1; i<=N; i++)
    {
        int v;
        for(v=cur; v!=root1 && S[i-NS[v].len-1]!=S[i]; v=NS[v].link);
        if(NS[v].chd[S[i]-'a']!=-1) cur=NS[v].chd[S[i]-'a'];
        else
        {
            int par=v;
            cur=newNode();
            
            for(v=NS[v].link; v!=root1 && S[i-NS[v].len-1]!=S[i]; v=NS[v].link);
            if(NS[v].chd[S[i]-'a']==-1) NS[cur].link=root2;
            else NS[cur].link=NS[v].chd[S[i]-'a'];
            
            NS[par].chd[S[i]-'a']=cur;
            NS[cur].len=NS[par].len+2;
        }
        //printf("%d : %d %d\n", cur, NS[cur].len, NS[cur].link);
        P[i]=cur;
    }
}

int dp[MAXN+10];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin>>S;
    N=S.size();
    S="?"+S;

    EERTREE(N, S);
    for(int i=1; i<=N; i++) dp[P[i]]++;
    ll ans=0;
    for(int i=ncnt-1; i>=0; i--)
    {
        ans=max(ans, (ll)dp[i]*NS[i].len);
        dp[NS[i].link]+=dp[i];
    }
    printf("%lld\n", ans);
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 44892 KB Output is correct
2 Correct 23 ms 44892 KB Output is correct
3 Correct 23 ms 44892 KB Output is correct
4 Correct 23 ms 44892 KB Output is correct
5 Correct 23 ms 44892 KB Output is correct
6 Correct 23 ms 44892 KB Output is correct
7 Correct 25 ms 44640 KB Output is correct
8 Correct 24 ms 44716 KB Output is correct
9 Correct 23 ms 44892 KB Output is correct
10 Correct 24 ms 44904 KB Output is correct
11 Correct 23 ms 44892 KB Output is correct
12 Correct 25 ms 44892 KB Output is correct
13 Correct 23 ms 44892 KB Output is correct
14 Correct 25 ms 44880 KB Output is correct
15 Correct 25 ms 44892 KB Output is correct
16 Correct 23 ms 44880 KB Output is correct
17 Correct 23 ms 44892 KB Output is correct
18 Correct 23 ms 44892 KB Output is correct
19 Correct 24 ms 44892 KB Output is correct
20 Correct 23 ms 44892 KB Output is correct
21 Correct 23 ms 44892 KB Output is correct
22 Correct 33 ms 44884 KB Output is correct
23 Correct 24 ms 44892 KB Output is correct
24 Correct 24 ms 44912 KB Output is correct
25 Correct 24 ms 44892 KB Output is correct
26 Correct 33 ms 44892 KB Output is correct
27 Correct 24 ms 44892 KB Output is correct
28 Correct 33 ms 45144 KB Output is correct
29 Correct 23 ms 44892 KB Output is correct
30 Correct 33 ms 44892 KB Output is correct
31 Correct 23 ms 44892 KB Output is correct
32 Correct 33 ms 44672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 44796 KB Output is correct
2 Correct 24 ms 44892 KB Output is correct
3 Correct 23 ms 44892 KB Output is correct
4 Correct 24 ms 44892 KB Output is correct
5 Correct 24 ms 44884 KB Output is correct
6 Correct 26 ms 44912 KB Output is correct
7 Correct 24 ms 44892 KB Output is correct
8 Correct 29 ms 44960 KB Output is correct
9 Correct 24 ms 44892 KB Output is correct
10 Correct 25 ms 44904 KB Output is correct
11 Correct 24 ms 44696 KB Output is correct
12 Correct 24 ms 44892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 44892 KB Output is correct
2 Correct 29 ms 44952 KB Output is correct
3 Correct 28 ms 44892 KB Output is correct
4 Correct 27 ms 45000 KB Output is correct
5 Correct 28 ms 45184 KB Output is correct
6 Correct 29 ms 44892 KB Output is correct
7 Correct 30 ms 45000 KB Output is correct
8 Correct 29 ms 44868 KB Output is correct
9 Correct 27 ms 44892 KB Output is correct
10 Correct 27 ms 44892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 45044 KB Output is correct
2 Correct 34 ms 45296 KB Output is correct
3 Correct 30 ms 45304 KB Output is correct
4 Correct 30 ms 45304 KB Output is correct
5 Correct 34 ms 45296 KB Output is correct
6 Correct 29 ms 45212 KB Output is correct
7 Correct 29 ms 45188 KB Output is correct
8 Correct 28 ms 45180 KB Output is correct
9 Correct 30 ms 45304 KB Output is correct
10 Correct 32 ms 45304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 45488 KB Output is correct
2 Correct 35 ms 45764 KB Output is correct
3 Correct 31 ms 45800 KB Output is correct
4 Correct 30 ms 45744 KB Output is correct
5 Correct 35 ms 46036 KB Output is correct
6 Correct 36 ms 45780 KB Output is correct
7 Correct 32 ms 45844 KB Output is correct
8 Correct 27 ms 45900 KB Output is correct
9 Correct 28 ms 45736 KB Output is correct
10 Correct 36 ms 45884 KB Output is correct
11 Correct 38 ms 45736 KB Output is correct
12 Correct 31 ms 45996 KB Output is correct