Submission #209733

#TimeUsernameProblemLanguageResultExecution timeMemory
209733jhnah917Palindromes (APIO14_palindrome)C++14
0 / 100
1101 ms38480 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pi; const ll p1 = 917, mod1 = 524287; const ll p2 = 179, mod2 = 993244853; struct Hashing{ vector<ll> ha, ba; ll p, mod; Hashing(){ } Hashing(string &s, ll p1, ll mod1) : p(p1), mod(mod1) { int n = s.size(); ha.resize(n+1); ba.resize(n+1); ba[0] = 1, ba[1] = p; for(int i=n-1; i>=0; i--) ha[i] = (ha[i+1] * p + s[i]) % mod; for(int i=2; i<=n; i++) ba[i] = ba[i-1] * p % mod; } int substr(int l, int r){ ll ret = ha[l] - ha[r+1] * ba[r-l+1]; ret %= mod; ret += mod; ret %= mod; return ret; } }h1, h2; int n; char inp[606060]; string s; int pal[606060]; map<pi, ll> mp[mod1]; //{h2, len} void manacher(){ for(int i=n-1; i>=0; i--){ inp[i << 1 | 1] = inp[i]; inp[i << 1] = '#'; } n <<= 1; inp[n++] = '#'; s = string(inp); int r = -1, p = -1; for(int i=0; i<n; i++){ pal[i] = (i <= r ? min(pal[p*2-i], r-i) : 0); while(i-pal[i]-1 >= 0 && i+pal[i]+1 < n && s[i-pal[i]-1] == s[i+pal[i]+1]) pal[i]++; if(i+pal[i] > r) r = i+pal[i], p = i; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> inp; s = string(inp); n = s.size(); h1 = Hashing(s, p1, mod1); h2 = Hashing(s, p2, mod2); manacher(); for(int i=0; i<n; i++){ if(!pal[i]) continue; if(i & 1){ for(int j=1; j<=pal[i]; j+=2){ int s = i/2 - j/2; int e = i/2 + j/2; mp[h1.substr(s, e)][pi(h2.substr(s, e), e-s+1)]++; } }else{ for(int j=2; j<=pal[i]; j+=2){ int s = i - j/2; s /= 2; int e = i + j/2; e /= 2; mp[h1.substr(s, e)][pi(h2.substr(s, e), e-s+1)]++; } } } ll ans = 0; for(int i=0; i<mod1; i++){ for(auto j : mp[i]){ //cout << j.second << " " << j.first.second << "\n"; ans = max(ans, j.second * j.first.second); } } 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...