Submission #1322261

#TimeUsernameProblemLanguageResultExecution timeMemory
1322261khbaPalindromes (APIO14_palindrome)C++20
0 / 100
0 ms332 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[i])) % 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[i])) % 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...