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;
void Z(const string& s, vector<int>& z) {
z.assign(s.size(), 0);
int n = s.size();
int x = 0, y = 0;
for (int i = 1; i < n; i++) {
z[i] = max(0, min(z[i-x], y-i+1));
while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
x = i; y = i+z[i]; z[i]++;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("palindrome.in", "r", stdin);
//freopen("palindrome.out", "w", stdout);
string s;
cin >> s;
int n = s.length();
vector<int> z, cnt(n + 1, 0);
vector<bool> pal(n + 1, false);
long long res = 0;
for (int i = 0; i < n; i++) {
string t = s.substr(i, n - i);
string rt = t;
reverse(rt.begin(), rt.end());
string t2 = t;
t2 += '#';
t2 += rt;
Z(t2, z);
for (int j = 0; j <= n - i; j++) {
pal[j] = false;
cnt[j] = 0;
}
for (int j = 0; j < n - i; j++) {
if (z[z.size() - j - 1] == j + 1) {
pal[j] = 1;
}
}
t += '#';
t += s;
Z(t, z);
for (int j = n - i + 1; j < (int) z.size(); j++) {
cnt[z[j]]++;
}
for (int j = n - i - 1; j >= 0; j--) {
cnt[j] += cnt[j + 1];
}
for (int j = i; j < n; j++) {
if (pal[j - i]) {
int len = j - i + 1;
res = max(res, cnt[len] * 1LL * len);
}
}
}
cout << res << '\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... |