#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define ll long long
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1002 + 10 , maxq = 1e7 + 1 , inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int lcp[maxn] ,dp[maxn] ;
signed main(){
ios::sync_with_stdio(false); cin.tie(0) ;
int t;
cin >> t ;
while(t--){
string s ;
cin >> s ;
int n = (int)s.size() ;
s = " " + s;
if(n%2==1)dp[n/2+1] = 1 ;
for(int i = n/2 ; i >= 1 ; i--){
int k =0 ;
lcp[i] = 0;
dp[i] = 1;
for(int j = i+1 ; j <= n/2 ; j++){
while(k!=0 && s[i+k] != s[j]){
k = lcp[i+k-1] ;
}
if(s[i+k] == s[j])k++;
lcp[j]= k ;
}
k =0 ;
for(int j = n+1 - n/2 ; j <= n-i+1 ; j++){
while(k!=0 && s[j] != s[i+k]){
k = lcp[i+k-1] ;
}
if(s[i+k] == s[j])k++;
lcp[j] = k ;
}
k = lcp[n-i+1] ;
while(k!=0){
dp[i] = max(dp[i] , dp[i+k] + 2) ;
k = lcp[k+i];
}
}
cout << dp[1] << "\n";
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10043 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10043 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10043 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10043 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |