This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// adil sultanov | vonat1us
#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {
#ifdef AM
freopen(".in", "r", stdin);
#endif
}
const bool flag = 0;
const int N = 1e5+10;
const int p = 31;
ll h[N], hr[N], po[N];
int mult(int a, int b) {
return a*1ll*b % MOD;
}
void ma1n() {
string s;
cin >> s;
int n = sz(s);
po[0] = 1;
for (int i = 1; i <= n; ++i) {
po[i] = mult(po[i-1], p);
}
for (int i = 0; i < n; ++i) {
h[i+1] = (h[i]*p + s[i]) % MOD;
}
reverse(all(s));
for (int i = 0; i < n; ++i) {
hr[i+1] = (hr[i]*p + s[i]) % MOD;
}
auto get = [&](int l, int r, int t) {
if (t) {
r = n-r+1;
l = n-l+1;
swap(l, r);
return (hr[r] - mult(hr[l-1], po[r-l+1]) + MOD) %MOD;
} else {
return (h[r] - mult(h[l-1], po[r-l+1]) + MOD) %MOD;
}
};
unordered_map<int, int> cnt;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
cnt[get(i, j, 0)]++;
}
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
if (get(i, j, 0) == get(i, j, 1)) {
ans = max(ans, cnt[get(i, j, 0)] * 1ll * (j-i+1));
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr), fin();
int ts = 1;
if (flag) {
cin >> ts;
}
while (ts--) {
ma1n();
}
return 0;
}
# | 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... |