제출 #647116

#제출 시각아이디문제언어결과실행 시간메모리
647116google회문 (APIO14_palindrome)C++17
0 / 100
1086 ms1628 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll P = 31,mxn = 10005,m = 1e9+7;
ll h[mxn],pows[mxn],N;
ll fin(int l, int r, bool rev = 0){
    ll ans;
    if (rev) {
        l = N-l-1;
        r = N-r-1;
        swap(l,r);
    }
    ans = h[r]-(l?h[l-1]:0);
    ans = (ans+m)%m;
    ans = (ans*pows[N-r-1])%m;
    return ans;
}
map<ll,pair<ll,ll>> pa;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    string s; cin >> s;
    N = int(s.size());
    for (int i = 0;i<N;i++){
        if (i){
            pows[i] = (pows[i-1]*P)%m;
            h[i] = h[i-1];
        }
        else{
            pows[i] = 1;
            h[i] = 0;
        }
        h[i] += pows[i]*(s[i]-'a'+1); 
    }
    for (int i = 0;i<N;i++){
        for (int j = 0;j<=i;j++){
            if (fin(j,i) == fin(j,i,1)){
                ll t = fin(j,i);
                pa[t].first++;
                pa[t].second = (i-j+1);
            }
        }
    }
    ll ans = 0;
    for (auto [a,b]:pa){
        ans = max(ans,b.first*b.second);
    }
    cout << ans;
    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...