Submission #399111

#TimeUsernameProblemLanguageResultExecution timeMemory
399111BERNARB01Palindromes (APIO14_palindrome)C++17
0 / 100
1093 ms8428 KiB
#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; string rs = s; reverse(rs.begin(), rs.end()); 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 t2 = t; t2 += '#'; t2 += rs; Z(t2, z); bitset<1000> pal(0); for (int j = 0; j < (int) s.length(); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...