이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7,P=47,mx=1e6+5;
ll h[mx],p[mx];
string s;
bool check(ll a,ll b,ll l) {
if(a>b) return false;
ll h1=h[a+l-1]-h[a-1];
ll h2=h[b+l-1]-h[b-1];
return (1LL*h1*p[b-a])%mod == h2;
}
void solve() {
cin >> s;
ll n=ll(s.size());
for(ll i=1;i<=n;++i) {
h[i]=(h[i-1]+(s[i-1]-'a'+1)*p[i-1])%mod;
h[i]%=mod;
}
ll l=1,r=n,res=0;
while(l<=r) {
ll k=1;
while(!check(l,r-k+1,k)) {
++k;
}
if(l == r-k+1) {
++res; break;
}
l+=k,r-=k;
res+=2;
}
cout << res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
p[0]=1;
for(int i=1;i<mx;++i) {
p[i]=(p[i-1]*P)%mod;
}
ll t; cin >> t;
while(t--) {
solve();
cout << '\n';
}
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... |