This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] * P % Mod;
p[i + 1] = (p[i] * P + (s[i] - 'a' + 1)) % Mod;
}
}
int get(int l, int r){
int v = p[r + 1] - (p[l] * pw[r - l + 1]) % Mod;
return v < 0 ? Mod + v : v;
}
};
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> 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |