Submission #542030

#TimeUsernameProblemLanguageResultExecution timeMemory
542030FatihSolakPalindromes (APIO14_palindrome)C++17
23 / 100
1077 ms34752 KiB
#include <bits/stdc++.h> #define N 300005 #define K 30 using namespace std; const int base = 31; const int mod = 1e9 + 7; const int base2 = 37; const int mod2 = 1e9 + 9; int cnt[N][K]; int val[N]; long long pre[N]; long long pw[N]; long long pre2[N]; long long pw2[N]; vector<int> palindromes[N]; void solve(){ string s; cin >> s; int n = s.size(); s = "." + s; for(int i=1;i<=n;i++){ pre[i] = (pre[i-1] * base + (s[i] - 'a'))%mod; pre2[i] = (pre2[i-1] * base2 + (s[i] - 'a'))%mod2; } long long ans = 0; map<string,int> mp; for(int i = n;i>=1;i--){ if(i == n || s[i+1] != s[i]){ val[i] = 1; } else val[i] = val[i+1] + 1; palindromes[i].push_back(i + val[i] - 1); cnt[val[i]][s[i] - 'a']++; for(auto u:palindromes[i+1]){ if(u + 1 <= n && s[u+1] == s[i] && u + 1 > i + val[i] - 1){ palindromes[i].push_back(u+1); } } for(auto u:palindromes[i]){ //cout << u << " " << s.substr(i,u - i + 1) << " "; ans = max(ans,1ll*(u-i + 1) * (++mp[s.substr(i,u - i + 1)])); } //cout << endl; } for(int i=n;i>=1;i--){ for(int c = 0;c<K;c++){ cnt[i][c] += cnt[i+1][c]; ans = max(ans,1ll*i*cnt[i][c]); } } cout << ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif pw[0] = 1; pw2[0] = 1; for(int i = 1;i<N;i++){ pw[i] = pw[i-1] * base % mod; pw2[i] = pw2[i-1] * base2 % mod2; } int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#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...