This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
vector<int>ans;
const int mod=1e9+5;
const int modd=31;
void fun(){
string s;
cin>>s;
int n=s.size();
int a=0,b=0;
int x=-1;
int p=0;
int mlt=1;
for(int i=0;i<n/2;i++){
a=(a*modd+s[i])%mod;
b=(s[n-i-1]*mlt+b)%mod;
mlt=(mlt*modd)%mod;
if(a==b){
x=i;
a=0,b=0;
p+=2;
mlt=1;
}
}
if(n%2 or x<n/2-1)p++;
ans.pb(p);
}
signed main(){
int t;
cin>>t;
while(t--)fun();
for(auto a:ans)cout<<a<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |