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;
using ll = long long;
int const p = 117;
int const mod = 1e9 + 9;
int const maxn = 10010;
char s[maxn];
int h[maxn];
int pw[maxn];
vector<int> hs(int n) {
vector<int> res(n+1);
for (int i = 1; i <= n; i++) {
res[i] = (ll(res[i-1])*p + s[i] ) % mod;
}
return res;
}
void init() {
pw[0] = 1;
for (int i = 1; i < maxn; i++)
pw[i] = ll(pw[i-1])*p%mod;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
init();
int n;
string si;
cin >> si;
n = si.size();
copy(si.begin(), si.end(), s+1);
auto fh = hs(n);
reverse(s+1, s+n+1);
auto rh = hs(n);
auto comp = [&] (int l, int r) -> pair<int, int> {
int x = (ll(fh[r]) - ll(fh[l-1])*pw[r-l+1]) % mod;
int y = (ll(rh[n-l+1]) - ll(rh[n-r])*pw[r-l+1]) % mod;
if (x < 0) x += mod;
if (y < 0) y += mod;
return {x == y, x};
};
ll ans = 0;
for (int lenght = 1; lenght <= n; lenght++) {
vector<int> v;
for (int l = 1; l + lenght - 1 <= n; l++) {
int r = l + lenght - 1;
auto x = comp(l, r);
if (x.first) {
v.push_back(x.second);
}
}
sort(v.begin(), v.end());
int best = 0;
for (int i = 0; i < (int)v.size(); i++) {
int l = i;
while (i < (int)v.size() and (i == 0 or v[i] == v[i-1])) i++;
best = max(best, i - l);
}
ans = max(ans, ll(lenght)*best);
}
cout << ans << "\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... |