제출 #1322262

#제출 시각아이디문제언어결과실행 시간메모리
1322262khba회문 (APIO14_palindrome)C++20
8 / 100
190 ms23828 KiB
#include "bits/stdc++.h" using namespace std; const int MOD = 1e9 + 9, base = 37; int32_t main() { ios ::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int n = s.size(); map<int, int> cnt; for (int i = 0; i < n; ++i) { int h = 0; for (int j = i; j < n; ++j) { h = (1LL * h * base + (int)(s[j])) % MOD; cnt[h]++; } } long long ans = 0; vector<vector<bool>> dp(n, vector<bool>(n)); for (int i = n - 1; ~i; --i) for (int j = i; j < n; ++j) if (i == j) dp[i][j] = true; else dp[i][j] = (j - i + 1 == 2 ? (s[i] == s[j]) : (dp[i + 1][j - 1] and s[i] == s[j])); for (int i = 0; i < n; ++i) { int h = 0; for (int j = i; j < n; ++j) { h = (1LL * h * base + (int)(s[j])) % MOD; if (dp[i][j]) ans = max(ans, 1LL * (int)(j - i + 1) * cnt[h]); } } cout << ans; }
#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...