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;
template<const int A>
class eertree {
private:
string s;
int n, id, cr, I;
vector<int> P, L, C;
vector<array<int, A>> T;
int par(int v) {
while (I - L[v] - 2 < 0 || s[I - L[v] - 2] != s[I - 1]) {
v = P[v];
}
return v;
}
void add() {
int ch = s[I++] - 'a';
cr = par(cr);
if (!T[cr][ch]) {
L[id] = 2 + L[cr];
P[id] = T[par(P[cr])][ch];
T[cr][ch] = id++;
}
cr = T[cr][ch];
C[cr]++;
}
public:
eertree() {}
eertree(const string& _s) {
s = _s;
n = s.length();
T.assign(n + 2, {});
L.assign(n + 2, 0);
P.assign(n + 2, 0);
C.assign(n + 2, 0);
P[0] = 1;
L[1] = -1;
id = 2;
cr = I = 0;
for (int i = 0; i < n; i++) {
add();
}
}
long long solve() {
vector<int> inDeg(n + 2, 0);
for (int i = 2; i < n + 2; i++) {
inDeg[P[i]]++;
}
vector<int> que;
for (int i = 2; i < n + 2; i++) {
if (inDeg[i] == 0) {
que.push_back(i);
}
}
for (int b = 0; b < (int) que.size(); b++) {
int u = que[b];
int v = P[u];
if (v < 2) {
continue;
}
C[v] += C[u];
inDeg[v]--;
if (inDeg[v] == 0) {
que.push_back(v);
}
}
long long res = 0;
for (int i = 2; i < n + 2; i++) {
res = max(res, C[i] * 1LL * L[i]);
}
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
eertree<26> pals(s);
cout << pals.solve() << '\n';
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... |