This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int N = 1e4 + 20;
int hsh[N], pw[N], n;
unordered_map<int, ll> cnt;
string s;
ll ans;
int getHash(int l, int r) {
if (l == 0) return hsh[r];
return hsh[r] - hsh[l - 1] * pw[r - l + 1];
}
bool isPal(int l, int r) {
if (r - l == 0) return 1;
int t = r - l + 1;
if (t % 2)
return getHash(l, l + t / 2 - 1) == getHash(l + t / 2 + 1, r);
else
return getHash(l, l + t / 2 - 1) == getHash(l + t / 2, r);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> s; n = s.size();
pw[0] = 1;
hsh[0] = s[0];
for (int i = 1; i < n; i++) {
pw[i] = pw[i - 1] * PR;
hsh[i] = PR * hsh[i - 1] + s[i];
}
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
if (isPal(i, j))
cnt[getHash(i, j)]++;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
ans = max(ans, cnt[getHash(i, j)] * (j - i + 1));
cout << ans << endl;
}
# | 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... |