이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
//"\n"
//algoritmo para calcular la cantidad de substrings diferentes
using namespace std;
const ll MOD=1e9+9;
const ll p=31;
int main()
{
int t;
string s;
cin>>t;
while(t--){
cin>>s;
ll n=s.size();
ll P[n+1];
ll h[n+2];
h[0]=0;
ll pot=1;
for(int i=0;i<n;i++){
ll x=s[i]-'a'+1;
P[i]=pot;
h[i+1]=(h[i]+x*pot)%MOD;
pot=(pot*p)%MOD;
}
int tam=1;
int izq=0,der=n-1;
int res=0;
if(n==1)res=1;
while(1){
if(izq+tam-1>=der-tam+1){
res++;
break;
}
ll a=(h[izq+tam]-h[izq]+MOD)%MOD;
a=(a*P[n-izq-1])%MOD;
ll b=(h[der+1]-h[der-tam+1]+MOD)%MOD;
b=(b*P[(n-1)-(der-tam+1)])%MOD;
if(a==b){
if(izq+tam==der-tam+1){
res+=2;
break;
}
izq+=tam;
der-=tam;
tam=1;
res+=2;
}else{
tam++;
}
}
cout<<res<<endl;
}
return 0;
}
//https://codeforces.com/contest/911/problem/D
//https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1021
# | 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... |