#include <bits/stdc++.h>
using namespace std;
#define int long long
int const N=10005;
int const mod=1e9+7;
int const base=727;
int dp[N];
int Hash[N];
int pw[N];
void pre(){
pw[0]=1;
for(int i=1;i<N;i++)
pw[i]=(pw[i-1]*base)%mod;
}
int make_hash(int l,int r){
l--;
int h=((Hash[r]-((Hash[l]*pw[r-l])%mod))+mod)%mod;
return h;
}
void solve(){
string s;
cin>>s;
int n=s.length();
int hsh=0;
for(int i=0;i<n;i++){
hsh*=base;
hsh%=mod;
hsh+=s[i];
hsh%=mod;
Hash[i+1]=hsh;
}
int ans=0;
for(int i=1;i<=(n/2);i++){
dp[i]=0;
for(int j=0;j<i;j++)
if(make_hash(j+1,i)==make_hash(n-(i-1),n-(j)))
dp[i]=max(dp[i],dp[j]+2);
ans=max(ans,dp[i]+(i*2<n));
}
cout<<ans<<endl;
}
signed main(){
pre();
int t;
cin>>t;
while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |