#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef int64_t ll;
const int N = 1e4 + 5;
const int P = 167;
const int mod = 1e9 + 7;
void solve(){
string s; cin >> s;
int n = s.size();
s = "#" + s;
int dp[n + 1] {}, h[n + 1] {}, pw[n + 1];
pw[0] = 1;
for(int i=1;i<=n;i++){
h[i] = (h[i - 1] * 1ll * P + s[i] - 'a') % mod;
pw[i] = pw[i-1] * 1ll * P % mod;
}
auto check = [&](int l, int r){
return (h[r] - h[l] * 1ll * pw[r - l] % mod + mod) % mod ==
(h[n - l] - h[n - r] * 1ll * pw[r - l] % mod + mod) % mod;
};
int res = 1;
for(int i=0;i<=n/2;i++){
for(int j=1;i + j<=n/2;j++){
if(check(i, i + j) && (i ? dp[i] : true)){
dp[i + j] = max(dp[i + j], dp[i] + 1);
}
}
res = max(res, dp[i] * 2 + 1);
}
cout<<res<<"\n";
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int t; cin>>t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |