#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <unordered_map>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007,N=1010;
const ull b = MOD;
string s,s2;
unsigned long long int hs[N],bs[N];
ll ans = 0;
unordered_map<ull, int> mp[N];
ull hsh(int i1, int i2) {
ull v1 = hs[i1] - hs[i2 + 1];
v1 *= bs[i1];
return v1;
}
int main() {
cin >> s;
bs[0] = 1;
for (int i = 1; i < N; i++)bs[i] = bs[i - 1] * b;
for (int i = s.size() - 1; i >= 0; i--) {
hs[i] = hs[i + 1] +((ull)s[i] - 'a') * bs[s.size() - 1 - i];
}
for (int i1 = 0; i1 < s.size(); i1++) {
for (int i2 = i1; i2 < s.size(); i2++) {
mp[i2 - i1 + 1][hsh(i1,i2)]++;
}
}
for (int i1 = 0; i1 < s.size(); i1++) {
for (int i2 = 0; i1 + i2 < s.size() && i1 - i2 >= 0; i2++) {
if (s[i1 + i2] != s[i1 - i2])break;
ll v1 = i2 * 2 + 1, v2 = mp[v1][hsh(i1 - i2, i1 + i2)];
ans = max(ans, v1 * v2);
}
for (int i2 = 0; i1 +1+i2 < s.size() && i1 - i2 >= 0; i2++) {
if (s[i1 + i2 + 1] != s[i1 - i2])break;
ll v1 = i2 * 2 + 2, v2 = mp[v1][hsh(i1 - i2, i1 + i2 + 1)];
ans = max(ans, v1 * v2);
}
}
cout << ans << endl;
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i1 = 0; i1 < s.size(); i1++) {
~~~^~~~~~~~~~
palindrome.cpp:37:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i2 = i1; i2 < s.size(); i2++) {
~~~^~~~~~~~~~
palindrome.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i1 = 0; i1 < s.size(); i1++) {
~~~^~~~~~~~~~
palindrome.cpp:43:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i2 = 0; i1 + i2 < s.size() && i1 - i2 >= 0; i2++) {
~~~~~~~~^~~~~~~~~~
palindrome.cpp:48:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i2 = 0; i1 +1+i2 < s.size() && i1 - i2 >= 0; i2++) {
~~~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
4 ms |
640 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
512 KB |
Output is correct |
2 |
Correct |
138 ms |
12092 KB |
Output is correct |
3 |
Correct |
20 ms |
384 KB |
Output is correct |
4 |
Correct |
243 ms |
19704 KB |
Output is correct |
5 |
Correct |
18 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
384 KB |
Output is correct |
7 |
Correct |
195 ms |
14812 KB |
Output is correct |
8 |
Correct |
17 ms |
512 KB |
Output is correct |
9 |
Correct |
283 ms |
20472 KB |
Output is correct |
10 |
Correct |
284 ms |
21924 KB |
Output is correct |
11 |
Correct |
275 ms |
21904 KB |
Output is correct |
12 |
Correct |
214 ms |
16832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
640 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 |
7 ms |
1024 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 |
13 ms |
1692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |