#include <bits/stdc++.h>
using namespace std;
const int64_t base=26,mod=1e9;
int64_t T,n,M[1000005],H[1000005];
char s[1000005];
int64_t GetHash(int64_t l,int64_t r)
{
return (H[r]-H[l-1]*M[r-l+1]+mod*mod)%mod;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
M[0]=1;
for(int64_t i=1;i<=1e6;i++)
M[i]=M[i-1]*base%mod;
cin>>T;
while(T--)
{
cin>>s+1;
n=strlen(s+1);
for(int64_t i=1;i<=n;i++)
H[i]=(H[i-1]*base+s[i])%mod;
int64_t l=1,r=n,res=0;
while(l<=r)
{
int64_t len=1;
while(l+len-1<r-len+1&&GetHash(l,l+len-1)!=GetHash(r-len+1,r))
len++;
if(l+len-1>=r-len+1)
{
res++;
break;
}
res+=2;
l+=len;
r-=len;
}
cout<<res<<"\n";
}
}
Compilation message
palindromic.cpp: In function 'int main()':
palindromic.cpp:23:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin>>s+1;
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8184 KB |
Output is correct |
2 |
Correct |
16 ms |
8304 KB |
Output is correct |
3 |
Correct |
16 ms |
8360 KB |
Output is correct |
4 |
Correct |
15 ms |
8360 KB |
Output is correct |
5 |
Correct |
16 ms |
8380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8184 KB |
Output is correct |
2 |
Correct |
16 ms |
8304 KB |
Output is correct |
3 |
Correct |
16 ms |
8360 KB |
Output is correct |
4 |
Correct |
15 ms |
8360 KB |
Output is correct |
5 |
Correct |
16 ms |
8380 KB |
Output is correct |
6 |
Correct |
15 ms |
8444 KB |
Output is correct |
7 |
Correct |
15 ms |
8448 KB |
Output is correct |
8 |
Correct |
15 ms |
8452 KB |
Output is correct |
9 |
Correct |
15 ms |
8500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8184 KB |
Output is correct |
2 |
Correct |
16 ms |
8304 KB |
Output is correct |
3 |
Correct |
16 ms |
8360 KB |
Output is correct |
4 |
Correct |
15 ms |
8360 KB |
Output is correct |
5 |
Correct |
16 ms |
8380 KB |
Output is correct |
6 |
Correct |
15 ms |
8444 KB |
Output is correct |
7 |
Correct |
15 ms |
8448 KB |
Output is correct |
8 |
Correct |
15 ms |
8452 KB |
Output is correct |
9 |
Correct |
15 ms |
8500 KB |
Output is correct |
10 |
Correct |
17 ms |
8632 KB |
Output is correct |
11 |
Correct |
15 ms |
8732 KB |
Output is correct |
12 |
Correct |
17 ms |
8804 KB |
Output is correct |
13 |
Correct |
16 ms |
8904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8184 KB |
Output is correct |
2 |
Correct |
16 ms |
8304 KB |
Output is correct |
3 |
Correct |
16 ms |
8360 KB |
Output is correct |
4 |
Correct |
15 ms |
8360 KB |
Output is correct |
5 |
Correct |
16 ms |
8380 KB |
Output is correct |
6 |
Correct |
15 ms |
8444 KB |
Output is correct |
7 |
Correct |
15 ms |
8448 KB |
Output is correct |
8 |
Correct |
15 ms |
8452 KB |
Output is correct |
9 |
Correct |
15 ms |
8500 KB |
Output is correct |
10 |
Correct |
17 ms |
8632 KB |
Output is correct |
11 |
Correct |
15 ms |
8732 KB |
Output is correct |
12 |
Correct |
17 ms |
8804 KB |
Output is correct |
13 |
Correct |
16 ms |
8904 KB |
Output is correct |
14 |
Correct |
149 ms |
27448 KB |
Output is correct |
15 |
Correct |
86 ms |
32736 KB |
Output is correct |
16 |
Correct |
135 ms |
41876 KB |
Output is correct |
17 |
Correct |
82 ms |
42804 KB |
Output is correct |