// 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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1404 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |