이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1, A = 26;
int L[N], P[N], T[N][A], C[N];
int sP[N], diff[N], SA[N];
int id, cr, II;
char s[N];
class eertree {
private:
int n;
int Pr(int v) {
while(s[II - L[v] - 2] != s[II - 1]) {
v = P[v];
}
return v;
}
void add(char c) {
int ch = c - 'a';
s[II++] = ch;
cr = Pr(cr);
if(!T[cr][ch]) {
L[id] = L[cr] + 2;
P[id] = T[Pr(P[cr])][ch];
diff[id] = L[id] - L[P[id]];
if(diff[id] == diff[P[id]]) {
sP[id] = sP[P[id]];
} else {
sP[id] = P[id];
}
T[cr][ch] = id++;
}
cr = T[cr][ch];
C[cr]++;
}
public:
eertree() {};
eertree(const string& _s) {
s[II++] = -1;
P[0] = 1;
L[1] = -1;
id = 2;
n = _s.length();
for (int i = 0; i < n; i++) {
add(_s[i]);
}
}
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 t;
cin >> t;
eertree pals(t);
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... |