This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
std::string s;
int n;
namespace Hash {
std::vector<long long> sp;
std::vector<long long> pBase;
const int MOD = 1e9 + 7;
const int BASE = 29;
void init() {
sp.resize(n + 1);
pBase.resize(n + 1);
sp[0] = 0;
pBase[0] = 1;
for (int i = 1; i <= n; i++) {
pBase[i] = pBase[i - 1] * BASE % MOD;
sp[i] = (sp[i - 1] * BASE + s[i - 1] - 'a') % MOD;
}
}
int get_hash(int l, int r) {
return ((sp[r + 1] - sp[l] * pBase[r - l + 1]) % MOD + MOD) % MOD;
}
}
void read() {
std::cin >> s;
n = s.length();
}
void solve() {
int l = 0, r = n - 1;
int ans = 0;
while (l <= r) {
ans++;
int sz = r - l + 1;
int lim = sz >> 1;
int lgmin = sz;
for (int lg = 1; lg <= lim; lg++) {
if (Hash::get_hash(l, l + lg - 1) == Hash::get_hash(r - lg + 1, r)) {
lgmin = lg;
ans++;
break;
}
}
l += lgmin;
r -= lgmin;
}
std::cout << ans << '\n';
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
read();
Hash::init();
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... |