이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42,base=29,mod=1e9+7;
int n;
long long pref[nmax],st[nmax];
long long get_hash(long long s,long long t)
{
long long ret=pref[t];
if(s)ret=ret-pref[s-1]*st[t-s+1];
ret=ret%mod;
ret=(ret+mod)%mod;
return ret;
}
int solve()
{
string s;
cin>>s;
n=s.size();
st[0]=1;
for(int i=1;i<=n;i++)st[i]=st[i-1]*base%mod;
for(int i=0;i<n;i++)
{
pref[i]=0;
if(i)pref[i]=pref[i-1]*base;
pref[i]=pref[i]+s[i]-'a'+1;
pref[i]=pref[i]%mod;
}
int ret=0,l=0,r=n-1;
while(l<=r)
{
for(int i=0;true;i++)
{
int l_other=l+i;
int r_other=r-i;
if(l_other>=r_other)return ret+1;
if(get_hash(l,l_other)==get_hash(r_other,r))
{
ret=ret+2;
l=l_other+1;
r=r_other-1;
break;
}
}
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int t;
cin>>t;
for(int i=1;i<=t;i++)cout<<solve()<<endl;
return 0;
}
# | 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... |