제출 #433553

#제출 시각아이디문제언어결과실행 시간메모리
433553misir회문 (APIO14_palindrome)C++14
100 / 100
30 ms37236 KiB
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc prllf("Case %d: ", cs)
#define tcn prllf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);


#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define F(i,a,b)      for(int i= a; i <= b; i++)
#define R(i,b,a)      for(int i= b; i >= a; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define sline(a) scanf("%[^\n]s",a)
#define Case(t) printf("Case %d:\n",t)

const int N = 300005;
int tree[N][26], link[N], id, t;
ll len[N], freq[N];
char str[N];

void extend(int p)
{
    while (str[p - len[t] - 1] != str[p]) t = link[t];
    int x = link[t];
    while (str[p - len[x] - 1] != str[p]) x = link[x];
    int c = str[p] - 'a';
    if (!tree[t][c])
    {
        tree[t][c] = ++id;
        len[id] = len[t] + 2;
        link[id] = len[id] == 1 ? 2 : tree[x][c];
    }
    t = tree[t][c];
    freq[t]++;
}

int main()
{
    /*
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    //*/

    int l = scanf("%s", str + 1);
    l = strlen(str + 1);

    len[1] = -1, link[1] = 1;
    len[2] = 0, link[2] = 1;
    id = t = 2;

   for(int i = 1; i <= l; i++) extend(i);

    ll m = 0;
    for(int i = id; i >= 3; i--) {
        freq[link[i]] += freq[i];
        m = max(m, freq[i] * len[i]);
    }
    printf("%lld\n", m);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...