이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
vector<int> z;
int n = s.length();
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);
bitset<1000> pal(0);
for (int j = 0; j < (int) z.size(); j++) {
if (z[z.size() - j - 1] == j + 1) {
pal[j] = 1;
}
}
t += '#';
t += s;
Z(t, z);
vector<long long> cnt(n + 1, 0);
for (int j = n - i; j < (int) z.size(); j++) {
cnt[z[j]]++;
}
for (int j = n - 1; j >= 0; j--) {
cnt[j] += cnt[j + 1];
}
for (int j = i; j < n; j++) {
long long len = j - i + 1;
if (!pal[j - i]) {
continue;
}
long long ans = cnt[len];
ans *= len;
res = max(res, ans);
}
}
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... |