#include <bits/stdc++.h>
#define MOD 1000000009LL
using namespace std;
long long parc[1000007],step[10000007];
int main()
{
step[0]=1;
for(int i=1;i<=1000001;i++) step[i]=(step[i-1]*30)%MOD;
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int n=s.size();
parc[n]=0;
for(int i=n-1;i>=0;i--) parc[i]=(30*parc[i+1]+(s[i]-'a'+1))%MOD;
long long st=1,hsh=0;
int prev=-1,cnt=1;
for(int i=0;i<n/2;i++)
{
hsh=(hsh+st*(s[i]-'a'+1))%MOD;
st=(st*30)%MOD;
if((parc[n-1-i]+MOD-((step[i-prev]*parc[n-1-prev])%MOD))%MOD==hsh)
{
st=1;
hsh=0;
cnt+=2;
prev=i;
}
}
if(prev==(n/2-1) && n%2==0) cnt--;
printf("%d\n",cnt);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8240 KB |
Output is correct |
4 |
Correct |
13 ms |
8248 KB |
Output is correct |
5 |
Correct |
13 ms |
8256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8240 KB |
Output is correct |
4 |
Correct |
13 ms |
8248 KB |
Output is correct |
5 |
Correct |
13 ms |
8256 KB |
Output is correct |
6 |
Correct |
13 ms |
8260 KB |
Output is correct |
7 |
Correct |
15 ms |
8392 KB |
Output is correct |
8 |
Correct |
13 ms |
8392 KB |
Output is correct |
9 |
Correct |
14 ms |
8504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8240 KB |
Output is correct |
4 |
Correct |
13 ms |
8248 KB |
Output is correct |
5 |
Correct |
13 ms |
8256 KB |
Output is correct |
6 |
Correct |
13 ms |
8260 KB |
Output is correct |
7 |
Correct |
15 ms |
8392 KB |
Output is correct |
8 |
Correct |
13 ms |
8392 KB |
Output is correct |
9 |
Correct |
14 ms |
8504 KB |
Output is correct |
10 |
Correct |
17 ms |
8528 KB |
Output is correct |
11 |
Correct |
16 ms |
8628 KB |
Output is correct |
12 |
Correct |
17 ms |
8716 KB |
Output is correct |
13 |
Correct |
20 ms |
8812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8240 KB |
Output is correct |
4 |
Correct |
13 ms |
8248 KB |
Output is correct |
5 |
Correct |
13 ms |
8256 KB |
Output is correct |
6 |
Correct |
13 ms |
8260 KB |
Output is correct |
7 |
Correct |
15 ms |
8392 KB |
Output is correct |
8 |
Correct |
13 ms |
8392 KB |
Output is correct |
9 |
Correct |
14 ms |
8504 KB |
Output is correct |
10 |
Correct |
17 ms |
8528 KB |
Output is correct |
11 |
Correct |
16 ms |
8628 KB |
Output is correct |
12 |
Correct |
17 ms |
8716 KB |
Output is correct |
13 |
Correct |
20 ms |
8812 KB |
Output is correct |
14 |
Correct |
468 ms |
19852 KB |
Output is correct |
15 |
Correct |
263 ms |
19852 KB |
Output is correct |
16 |
Correct |
436 ms |
28160 KB |
Output is correct |
17 |
Correct |
262 ms |
29304 KB |
Output is correct |