#include<bits/stdc++.h>
#define M 1000000013
#define maxn 300005
using namespace std;
typedef long long ll;
ll mul(ll a, ll b) {
return a * b % M;
}
ll norm(ll a) {
return (a < 0 ? a + M : a >= M ? a - M : a);
}
char a[maxn];
ll h[maxn], ih[maxn];
ll p[maxn];
int get(ll h[], int l, int r) {
return norm(h[r] - mul(h[l - 1], p[r - l + 1]));
}
int main(){
#define TASK "ABC"
//freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> a + 1;
int n = strlen(a + 1);
p[0] = 1;
for (int i = 1; i <= n; ++i)
p[i] = mul(p[i - 1], 26);
h[0] = 0;
for (int i = 1; i <= n; ++i)
h[i] = norm(mul(h[i - 1], 26) + a[i]);
ih[0] = 0;
for (int i = 1; i <= n; ++i)
ih[i] = norm(mul(ih[i - 1], 26) + a[n - i + 1]);
ll ans = 0;
for (int len = 0; len < n; ++len) {
map < ll, ll > mp;
for (int i = 1; i + len <= n; ++i) {
ll ret = get(h, i, i + len);
if (ret != get(ih, n + 1 - i - len, n + 1 - i)) continue;
ans = max(ans, (++mp[ret]) * (len + 1));
}
}
cout << ans << '\n';
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin >> a + 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
384 KB |
Output is correct |
2 |
Correct |
13 ms |
384 KB |
Output is correct |
3 |
Correct |
12 ms |
384 KB |
Output is correct |
4 |
Correct |
13 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
12 ms |
384 KB |
Output is correct |
9 |
Correct |
14 ms |
384 KB |
Output is correct |
10 |
Correct |
13 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
384 KB |
Output is correct |
12 |
Correct |
13 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
694 ms |
640 KB |
Output is correct |
2 |
Correct |
791 ms |
640 KB |
Output is correct |
3 |
Correct |
748 ms |
664 KB |
Output is correct |
4 |
Correct |
802 ms |
760 KB |
Output is correct |
5 |
Correct |
908 ms |
760 KB |
Output is correct |
6 |
Correct |
893 ms |
640 KB |
Output is correct |
7 |
Correct |
874 ms |
760 KB |
Output is correct |
8 |
Correct |
894 ms |
640 KB |
Output is correct |
9 |
Correct |
884 ms |
760 KB |
Output is correct |
10 |
Correct |
895 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
2944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
7808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |