#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 6;
const int base = 53;
const int MOD = 1e9 + 7;
int H[mxN], P[mxN];
int get_hash(int l, int r){
return (1LL * H[r] - 1LL * H[l - 1] * P[r - l + 1] % MOD + MOD) % MOD;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
P[0] = 1;
for(int i = 1;i < mxN;++i){
P[i] = 1LL * P[i - 1] * base % MOD;
}
int t;
cin >> t;
while(t--){
string str;
cin >> str;
int n = (int)str.size();
str = '$' + str;
for(int i = 1;i <= n;++i){
H[i] = (1LL * H[i - 1] * base % MOD + (str[i] - 'a' + 1)) % MOD;
}
vector<int>dp(n + 1, 1);
dp[n / 2] = n % 2;
for(int i = n / 2 - 1;i >= 0;--i){
for(int j = 1;2 * j <= n - 2 * i;++j){
// cout << i << ": " << j << "\n";
if(get_hash(i + 1, i + j) == get_hash(n - i - j + 1, n - i))dp[i] = max(dp[i], dp[i + j] + 2);
}
// cout << i << ": dp = " << dp[i] << '\n';
}
cout << dp[0] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4184 KB |
Output is correct |
2 |
Correct |
6 ms |
4184 KB |
Output is correct |
3 |
Correct |
6 ms |
4192 KB |
Output is correct |
4 |
Correct |
6 ms |
4348 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4184 KB |
Output is correct |
2 |
Correct |
6 ms |
4184 KB |
Output is correct |
3 |
Correct |
6 ms |
4192 KB |
Output is correct |
4 |
Correct |
6 ms |
4348 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
7 ms |
4184 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4188 KB |
Output is correct |
9 |
Correct |
7 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4184 KB |
Output is correct |
2 |
Correct |
6 ms |
4184 KB |
Output is correct |
3 |
Correct |
6 ms |
4192 KB |
Output is correct |
4 |
Correct |
6 ms |
4348 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
7 ms |
4184 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4188 KB |
Output is correct |
9 |
Correct |
7 ms |
4184 KB |
Output is correct |
10 |
Correct |
737 ms |
4564 KB |
Output is correct |
11 |
Correct |
355 ms |
4516 KB |
Output is correct |
12 |
Correct |
650 ms |
4500 KB |
Output is correct |
13 |
Correct |
489 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4184 KB |
Output is correct |
2 |
Correct |
6 ms |
4184 KB |
Output is correct |
3 |
Correct |
6 ms |
4192 KB |
Output is correct |
4 |
Correct |
6 ms |
4348 KB |
Output is correct |
5 |
Correct |
6 ms |
4356 KB |
Output is correct |
6 |
Correct |
7 ms |
4184 KB |
Output is correct |
7 |
Correct |
7 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4188 KB |
Output is correct |
9 |
Correct |
7 ms |
4184 KB |
Output is correct |
10 |
Correct |
737 ms |
4564 KB |
Output is correct |
11 |
Correct |
355 ms |
4516 KB |
Output is correct |
12 |
Correct |
650 ms |
4500 KB |
Output is correct |
13 |
Correct |
489 ms |
4444 KB |
Output is correct |
14 |
Execution timed out |
10088 ms |
14356 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |