이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100006;
const long long INF = (ll)1000000000000000007;
const ll P = 13084673;
void solve() {
string s;
cin >> s;
int i = 0, j = s.length() - 1, ans = 0;
ll hash1 = 0, hash2 = 0, pw = 1;
while (i < j) {
hash1 += (ll)(s[i] - 'a' + 1)*pw;
hash2 = hash2*P + (ll)(s[j] - 'a' + 1);
//cout << hash1 << " " << hash2 << endl;
pw *= P;
i++;
j--;
if (hash1 == hash2) {
ans += 2;
pw = 1;
hash2 = 0;
hash1 = 0;
}
}
if (pw == 1 && i==j+1)
cout << ans << endl;
else
cout << ans + 1 << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
solve();
}
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... |