Submission #734599

#TimeUsernameProblemLanguageResultExecution timeMemory
734599Alihan_8회문 (APIO14_palindrome)C++17
23 / 100
1074 ms20568 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
//#define int long long

template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag = false;
    if ( x > y ){
        x = y; flag |= true;
    }
    return flag;
}

template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag = false;
    if ( x < y ){
        x = y; flag |= true;
    }
    return flag;
}

struct Hash{
    const int Mod = 1e9 + 7, P = 29;
    int n;
    vector <int> p, pw;
    Hash(string s) : n((int)s.size()), p(n + 1), pw(n + 1, 1) {
        for ( int i = 0; i < n; i++ ){
            pw[i + 1] = pw[i] * 1ll * P % Mod;
            p[i + 1] = (p[i] * 1ll * P + (s[i] - 'a' + 1)) % Mod;
        }
    }
    int get(int l, int r){
        int v = p[r + 1] - (p[l] * 1ll * pw[r - l + 1]) % Mod;
        return v < 0 ? Mod + v : v;
    }
};

struct custom_hash{
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;
    int n = (int)s.size();
    Hash u(s);
    unordered_map <int,int,custom_hash> cnt[n + 1];
    for ( int i = 0; i < n; i++ ){
        int l = i, r = i;
        while ( l >= 0 and r < n and s[l] == s[r] ){
            cnt[r - l + 1][u.get(l, r)]++;
            l--, r++;
        }
        l = i, r = i + 1;
        while ( r < n and l >= 0 and s[l] == s[r] ){
            cnt[r - l + 1][u.get(l, r)]++;
            l--, r++;
        }
    }
    int Mx = 0;
    for ( int len = 1; len <= n; len++ ){
        for ( auto [l, r]: cnt[len] ){
            chmax(Mx, len * r);
        }
    }
    cout << Mx;

    cout << '\n';
}
#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...