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;
#define ll long long
const int N = 300'005;
struct node {
int nxt[26];
int len, suflink, cnt;
node() {
memset(nxt, 0, sizeof nxt);
len = suflink = cnt = 0;
}
} tree[N];
int nodes = 0, suf;
void build() {
nodes++;
tree[nodes].len = -1;
tree[nodes].suflink = nodes;
nodes++;
tree[nodes].len = 0;
tree[nodes].suflink = nodes - 1;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
string s;
cin >> s;
int n = s.size();
build();
suf = 1;
for (int i = 0; i < n; i++) {
int cur = suf;
while (i - tree[cur].len - 1 < 0 || s[i - tree[cur].len - 1] != s[i]) {
cur = tree[cur].suflink;
}
// cout << i << ": " << cur << '\n';
bool old = 1;
if (!tree[cur].nxt[s[i] - '0']) {
old = 0;
nodes++;
tree[cur].nxt[s[i] - '0'] = nodes;
tree[nodes].len = tree[cur].len + 2;
}
int p = tree[cur].nxt[s[i] - '0'];
tree[p].cnt++;
suf = p;
if (old) continue;
cur = tree[cur].suflink;
while (i - tree[cur].len - 1 < 0 || s[i - tree[cur].len - 1] != s[i]) {
cur = tree[cur].suflink;
}
tree[p].suflink = max(cur, 2);
}
ll ans = 0;
for (int i = 1; i <= nodes; i++) {
ans = max(ans, 1ll * tree[i].len * tree[i].cnt);
}
cout << ans << '\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... |