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;
const int nax = 3e5 + 3;
string s;
int n;
int len[nax], link[nax];
int tree[nax][26];
int occ[nax], t = 1;
int idx = 0;
long long ans = 0;
void extend(int p) {
while(s[p - len[t] - 1] != s[p]) t = link[t];
int x = link[t];
while(s[p - len[x] - 1] != s[p]) x = link[x];
int c = s[p] - 'a';
if(!tree[t][c]) {
tree[t][c] = ++idx;
len[idx] = len[t] + 2;
link[idx] = len[idx] == 1 ? 2 : tree[x][c];
} t = tree[t][c];
++occ[t];
}
void PlayGround() {
cin>>s;
n = s.size();
s = '#' + s; //1 based indexing (must for this implementation)
len[1] = -1, link[1] = 1; //odd len root
len[2] = 0, link[2] = 1; //even len root
t = idx = 2;
for(int i=1; i<=n; ++i) {
extend(i);
}
for(int i=idx; i>2; --i) {
ans = max(ans, len[i] * 1LL * occ[i]);
occ[link[i]] += occ[i];
}
cout<<ans<<'\n';
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
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... |