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 <bits/stdc++.h>
typedef std::string st;
typedef long long ll;
using namespace std;
ll p[1000006], h[1000006];
ll a, n, l, c, i;
ll h1, h2;
st t;
bool f;
bool check_equal(ll a, ll b, ll l) {
h1 = (h[a + l - 1] - h[a - 1]) * p[b - a];
h2 = (h[b + l - 1] - h[b - 1]);
return h1 == h2;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> a;
while (a --) {
cin >> t;
n = t.size();
p[0] = 1, p[1] = 47;
for (i = 2; i < n; i ++) {
p[i] = p[i - 1] * p[1];
}
h[0] = 0;
for (i = 1; i <= n; i ++) {
h[i] = h[i - 1] + (t[i - 1] - 'a' + 1) * p[i - 1];
}
l = 1, c = 0;
while (l <= n / 2 + (n % 2)) {
i = 1, f = false;
for (; i <= n / 2 - l + 1; i ++) {
// cout << t.substr(l-1, i) << ' ' << t.substr(n - l - i + 1, i) << '\n';
if (check_equal(l, n - l - i + 2, i)) {
// cout << "fuck you\n";
c += 2;
l = l + i;
f = true;
break;
}
}
if (!f) {
// cout << "HEY\n";
// cout << l << '\n';
c ++;
break;
}
}
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... |