This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |