#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+29;
const int mod = 1e9+7;
int mul(int x, int y){
x*=y;
x-=(x/mod)*mod;
return x;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
vector<int> p(1e6+38);
p[0] = 1;
for(int i=1; i<=1e6; i++){
p[i] = mul(p[i-1], 29);
}
while(t--){
string s; cin >> s;
int n = s.size();
int sum=0, ans=0;
vector<int> va(n);
for(int i=0; i<n; i++){
sum+=mul((s[i]-'a'+1),p[i+1]);
if(sum>=mod) sum-=mod;
va[i]=sum;
}
int s2=0, l=0, plast=n;
int siz=0;
for(int i=n-1; i>=n/2; i--){
s2=mul(s2, 29);
s2+=mul((s[i]-'a'+1), 29);
if(s2>=mod) s2-=mod;
int val= (l+ mul(s2, p[n-plast]));
if(val>=mod) val-=mod;
if(val==va[n-i-1]){
ans+=2;
siz+=(plast-i)*2;
if(siz>n) ans--, siz-=(plast-i);
l=val;
s2=0;
plast=i;
}
}
if(siz!=n) ans++;
cout<<ans<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8284 KB |
Output is correct |
3 |
Correct |
9 ms |
8284 KB |
Output is correct |
4 |
Correct |
9 ms |
8284 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8284 KB |
Output is correct |
3 |
Correct |
9 ms |
8284 KB |
Output is correct |
4 |
Correct |
9 ms |
8284 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
9 ms |
8284 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
9 ms |
8284 KB |
Output is correct |
9 |
Correct |
9 ms |
8112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8284 KB |
Output is correct |
3 |
Correct |
9 ms |
8284 KB |
Output is correct |
4 |
Correct |
9 ms |
8284 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
9 ms |
8284 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
9 ms |
8284 KB |
Output is correct |
9 |
Correct |
9 ms |
8112 KB |
Output is correct |
10 |
Correct |
10 ms |
8284 KB |
Output is correct |
11 |
Correct |
9 ms |
8300 KB |
Output is correct |
12 |
Correct |
11 ms |
8300 KB |
Output is correct |
13 |
Correct |
10 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8284 KB |
Output is correct |
3 |
Correct |
9 ms |
8284 KB |
Output is correct |
4 |
Correct |
9 ms |
8284 KB |
Output is correct |
5 |
Correct |
9 ms |
8280 KB |
Output is correct |
6 |
Correct |
9 ms |
8284 KB |
Output is correct |
7 |
Correct |
9 ms |
8284 KB |
Output is correct |
8 |
Correct |
9 ms |
8284 KB |
Output is correct |
9 |
Correct |
9 ms |
8112 KB |
Output is correct |
10 |
Correct |
10 ms |
8284 KB |
Output is correct |
11 |
Correct |
9 ms |
8300 KB |
Output is correct |
12 |
Correct |
11 ms |
8300 KB |
Output is correct |
13 |
Correct |
10 ms |
8284 KB |
Output is correct |
14 |
Correct |
84 ms |
19632 KB |
Output is correct |
15 |
Correct |
53 ms |
18636 KB |
Output is correct |
16 |
Correct |
83 ms |
18808 KB |
Output is correct |
17 |
Correct |
44 ms |
13804 KB |
Output is correct |