#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= l; --i)
#define ALL(x) (x).begin(), (x).end()
using i64 = long long;
using u64 = unsigned long long;
constexpr u64 mod = (1ull << 61) - 1;
constexpr u64 base = 239983;
u64 safeMod(u64 v) {
if (v < 0) v += mod;
return v % mod;
}
struct SH {
static constexpr u64 mul(u64 a, u64 b) {
__uint128_t x = (__uint128_t)(a) * (__uint128_t)(b);
return x % mod;
}
int n;
string S;
vector<u64> hash;
SH(string s) : S(s) {
n = (int)S.size();
hash.assign(n + 1, 0);
rep(i, 0, n) {
hash[i + 1] = (mul(hash[i], base) + (u64)(S[i] - 'a')) % mod;
}
}
};
void main_() {
string S;
cin >> S;
const int N = (int)S.size();
string A = S.substr(0, N / 2), B = S.substr(N - N / 2, N / 2);
const int M = (int)A.size();
vector<u64> baseTable(M + 10);
baseTable[0] = 1;
rep(i, 1, M + 10) baseTable[i] = SH::mul(baseTable[i - 1], base);
SH ha(A), hb(B);
auto judge = [&](int l, int r) {
u64 hs1 = safeMod(ha.hash[r] - SH::mul(ha.hash[l], baseTable[r - l]));
u64 hs2 = safeMod(hb.hash[M - l] - SH::mul(hb.hash[M - r], baseTable[r - l]));
return hs1 == hs2;
};
int l = 0, r = 0;
int ans = 0;
while (true) {
while (r != M) {
++r;
if (judge(l, r)) {
break;
}
}
if (not judge(l, r)) {
++ans;
break;
}
ans += 2;
l = r;
if (l == M) {
if (N % 2 == 1) ++ans;
break;
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) main_();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |