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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
const ll SIG = 26;
int nxt[MAXN][SIG], F[MAXN], len[MAXN], sz, v, cnt[MAXN];
string s;
inline void add(int pos) {
while (pos - 1 - len[v] < 0 || s[pos] != s[pos - 1 - len[v]])
v = F[v];
int c = s[pos] - 'a';
if (!nxt[v][c]) {
nxt[v][c] = ++sz;
len[sz] = len[v] + 2;
v = F[v];
while (s[pos] != s[pos - 1 - len[v]]) v = F[v];
if (len[sz] > 1) F[sz] = nxt[v][c];
else F[sz] = 1;
v = sz;
cnt[sz]++;
} else {
v = nxt[v][c];
cnt[v]++;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
sz = v = 1;
len[0] = -1;
len[1] = F[1] = 0;
cin >> s;
for (int i = 0; i < int(s.size()); i++)
add(i);
ll ans = 0;
for (int i = sz; i > 0; i--) {
ans = max(ans, 1ll * cnt[i] * len[i]);
cnt[F[i]] += cnt[i];
}
cout << ans << endl;
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... |