#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000005,MOD=1e9+7,inv=280000002;
int pref[MAXN],pkt[MAXN];
int dp[MAXN],N;
int get(int L,int R){
if(L>R)return 0;
return (pref[R]-((1LL*pref[L-1]*pkt[R-L+1])%MOD)+MOD)%MOD;
}
int DP(int L){
int R=N+1-L;
if(L>R)return 0;
int &ret=dp[L];
if(ret!=-1)return ret;
ret=1;
for(int i=1;i<=(R-L+1)/2;i++){
if(get(L,L+i-1)==get(R-i+1,R)){
ret=max(ret,2+DP(L+i));
return ret;
}
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
string s;
cin >> t;
while(t--){
cin >> s;
N=(int)s.length();
pkt[0]=1;
for(int i=0;i<N;i++){
pref[i+1]=(26LL*pref[i]+s[i]-'a')%MOD;
pkt[i+1]=(26LL*pkt[i])%MOD;
}
memset(dp,-1,sizeof(dp));
cout << DP(1) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Output is correct |
2 |
Correct |
5 ms |
4204 KB |
Output is correct |
3 |
Correct |
4 ms |
4204 KB |
Output is correct |
4 |
Correct |
4 ms |
4204 KB |
Output is correct |
5 |
Correct |
4 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Output is correct |
2 |
Correct |
5 ms |
4204 KB |
Output is correct |
3 |
Correct |
4 ms |
4204 KB |
Output is correct |
4 |
Correct |
4 ms |
4204 KB |
Output is correct |
5 |
Correct |
4 ms |
4204 KB |
Output is correct |
6 |
Correct |
4 ms |
4204 KB |
Output is correct |
7 |
Correct |
4 ms |
4204 KB |
Output is correct |
8 |
Correct |
6 ms |
4204 KB |
Output is correct |
9 |
Correct |
6 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Output is correct |
2 |
Correct |
5 ms |
4204 KB |
Output is correct |
3 |
Correct |
4 ms |
4204 KB |
Output is correct |
4 |
Correct |
4 ms |
4204 KB |
Output is correct |
5 |
Correct |
4 ms |
4204 KB |
Output is correct |
6 |
Correct |
4 ms |
4204 KB |
Output is correct |
7 |
Correct |
4 ms |
4204 KB |
Output is correct |
8 |
Correct |
6 ms |
4204 KB |
Output is correct |
9 |
Correct |
6 ms |
4204 KB |
Output is correct |
10 |
Correct |
6 ms |
4716 KB |
Output is correct |
11 |
Correct |
5 ms |
4460 KB |
Output is correct |
12 |
Correct |
7 ms |
4460 KB |
Output is correct |
13 |
Correct |
6 ms |
4460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4204 KB |
Output is correct |
2 |
Correct |
5 ms |
4204 KB |
Output is correct |
3 |
Correct |
4 ms |
4204 KB |
Output is correct |
4 |
Correct |
4 ms |
4204 KB |
Output is correct |
5 |
Correct |
4 ms |
4204 KB |
Output is correct |
6 |
Correct |
4 ms |
4204 KB |
Output is correct |
7 |
Correct |
4 ms |
4204 KB |
Output is correct |
8 |
Correct |
6 ms |
4204 KB |
Output is correct |
9 |
Correct |
6 ms |
4204 KB |
Output is correct |
10 |
Correct |
6 ms |
4716 KB |
Output is correct |
11 |
Correct |
5 ms |
4460 KB |
Output is correct |
12 |
Correct |
7 ms |
4460 KB |
Output is correct |
13 |
Correct |
6 ms |
4460 KB |
Output is correct |
14 |
Correct |
215 ms |
45704 KB |
Output is correct |
15 |
Correct |
104 ms |
33288 KB |
Output is correct |
16 |
Correct |
154 ms |
22408 KB |
Output is correct |
17 |
Correct |
111 ms |
20232 KB |
Output is correct |