#include <bits/stdc++.h>
using namespace std;
const int p1=997,r1=1000000007,p2=1439,r2=1000000009;
int t,ans;
string s;
void solve(int l,int r) {
int h1=0,h2=0,h3=0,h4=0,s1=1,s2=1;
//cout<<l<<" "<<r<<endl;
while (h1!=h2 || h3!=h4 || !h1) {
// cout<<l<<" "<<r<<endl;
if (l>=r) {
ans++;
return;
}
s1=(s1*p1)%r1;
s2=(s2*p2)%r2;
h1=(h1+s1*(s[l]-'a'+1))%r1;
h3=(h3+s2*(s[l]-'a'+1))%r2;
h2=((h2+(s[r]-'a'+1))*p1)%r1;
h4=((h4+(s[r]-'a'+1))*p2)%r2;
// cout<<"OK"<<endl;
// cout<<h1<<" "<<h2<<endl;
// cout<<h3<<" "<<h4<<endl;
l++;r--;
}
ans+=2;
if (l<=r)
solve(l,r);
}
int main() {
cin>>t;
while (cin>>s) {
ans=0;
solve(0,s.length()-1);
cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |