이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const long long m = 1000000007;
const long long p = 999999893;
long long power[maxn] = {};
int main()
{
// preprocess
power[0] = 1;
for (int i = 1; i < maxn; i++)
power[i] = (power[i-1] * p) % m;
// get number of test cases
int T; cin >> T;
// solve test cases
for (int t = 0; t < T; t++)
{
string s; cin >> s;
int n = s.length();
int base = 0, ans = 0;
long long hash1 = 0, hash2 = 0;
for( int i=0, j=n-1; i < n-i; i++, j--)
{
hash1 = (hash1 + s[i] * power[i]) % m;
hash2 = (hash2 + s[j] * power[j]) % m;
bool flag = true;
for (int k = base; k <= i; k++)
if (s[k] != s[j+(k-base)]) {
flag = false;
break;
}
if (flag) {
ans += 2 - (i == j);
hash1 = hash2 = 0;
base = i + 1;
}
}
if (hash1 != 0)
ans += 1;
cout << ans << 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... |