#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
const int maxn = 1e6+10;
const int MOD = 1e9+7;
int pw[maxn], h[maxn], h2[maxn], A = 9973;
string s;
unordered_map<int,int> M;
void comp_hash(string s, int h[])
{
h[0] = 1;
for(int i = 0; i < (int)s.size(); i++)
h[i+1] = ((h[i]*A)%MOD+s[i])%MOD;
}
int get_hash(int a, int b, int h[]){
return (h[b+1]-(h[a]*pw[b-a+1])%MOD+MOD)%MOD;
}
int mir(int ind){return (int)s.size()-ind-1;}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> s; pw[0] = 1;
for(int i = 1; i<maxn; i++) pw[i] = (pw[i-1]*A)%MOD;
int ans = 0, n = (int)s.size();
comp_hash(s,h); reverse(all(s)); comp_hash(s,h2); reverse(all(s));
for(int i = 0; i < n; i++)
for(int j = i; j < n; j++)
M[get_hash(i,j,h)]+=j-i+1;
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
int mid = (i+j)/2;
if(i!=j and get_hash(i,mid-(j-i+1)%2,h)
!=get_hash(mir(j),mir(mid+1),h2)) continue;
ans = max(ans, M[get_hash(i,j,h)]);
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8140 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
8 ms |
8140 KB |
Output is correct |
4 |
Correct |
8 ms |
8148 KB |
Output is correct |
5 |
Correct |
8 ms |
8152 KB |
Output is correct |
6 |
Correct |
9 ms |
8148 KB |
Output is correct |
7 |
Correct |
8 ms |
8140 KB |
Output is correct |
8 |
Correct |
8 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8148 KB |
Output is correct |
10 |
Correct |
9 ms |
8124 KB |
Output is correct |
11 |
Correct |
8 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8164 KB |
Output is correct |
13 |
Correct |
8 ms |
8140 KB |
Output is correct |
14 |
Correct |
8 ms |
8140 KB |
Output is correct |
15 |
Correct |
8 ms |
8164 KB |
Output is correct |
16 |
Correct |
7 ms |
8148 KB |
Output is correct |
17 |
Correct |
9 ms |
8136 KB |
Output is correct |
18 |
Correct |
8 ms |
8152 KB |
Output is correct |
19 |
Correct |
9 ms |
8144 KB |
Output is correct |
20 |
Correct |
10 ms |
8148 KB |
Output is correct |
21 |
Correct |
9 ms |
8276 KB |
Output is correct |
22 |
Correct |
9 ms |
8276 KB |
Output is correct |
23 |
Correct |
9 ms |
8144 KB |
Output is correct |
24 |
Correct |
8 ms |
8276 KB |
Output is correct |
25 |
Correct |
8 ms |
8140 KB |
Output is correct |
26 |
Correct |
8 ms |
8276 KB |
Output is correct |
27 |
Correct |
8 ms |
8276 KB |
Output is correct |
28 |
Correct |
8 ms |
8268 KB |
Output is correct |
29 |
Correct |
9 ms |
8276 KB |
Output is correct |
30 |
Correct |
8 ms |
8276 KB |
Output is correct |
31 |
Correct |
9 ms |
8276 KB |
Output is correct |
32 |
Correct |
8 ms |
8276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
8264 KB |
Output is correct |
2 |
Correct |
95 ms |
19188 KB |
Output is correct |
3 |
Correct |
35 ms |
8148 KB |
Output is correct |
4 |
Correct |
140 ms |
27568 KB |
Output is correct |
5 |
Correct |
35 ms |
8148 KB |
Output is correct |
6 |
Correct |
35 ms |
8148 KB |
Output is correct |
7 |
Correct |
116 ms |
21552 KB |
Output is correct |
8 |
Correct |
33 ms |
8148 KB |
Output is correct |
9 |
Correct |
138 ms |
28184 KB |
Output is correct |
10 |
Correct |
145 ms |
29164 KB |
Output is correct |
11 |
Correct |
204 ms |
29128 KB |
Output is correct |
12 |
Correct |
135 ms |
27464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
9048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
19392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
37820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |