이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
int t, p = 47;
cin>>t;
vector<ll> pw(1000001);
pw[0] = 1;
for (int i = 1; i <= 1000001; i++){
pw[i] = (pw[i - 1] * p) % mod;
}
for (int it = 0; it < t; it++){
string s;
cin>>s;
int l = 0, lind = -1, r = s.size() - 1;
ll lhash = 0, rhash = 0, c = 0;
while (l < r){
lind++;
lhash += s[l] * pw[lind];
lhash %= mod;
rhash = rhash * p + s[r];
rhash %= mod;
if (lhash == rhash){
c += 2;
lhash = 0;
rhash = 0;
lind = -1;
}
l++;
r--;
}
if (l == r || lhash != 0 || rhash != 0){
c++;
}
cout<<c<<"\n";
}
}
# | 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... |