#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <time.h>
#include <stack>
#include <queue>
#include <random>
#include <fstream>
#define endl '\n'
#define flush fflush(stdout), cout.flush()
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
const ll hs = 199;
const ldb eps = 1e-9, pi = acos(-1);
using namespace std;
const int maxn = 1e6 + 1;
const int p[3] = { 157, 163, 167 };
const int mod[3] = { (int)1e9 + 7, (int)1e9 + 9, (int)1e9 + 21 };
ll pw[3][maxn];
void preprocess() {
for (int i = 0; i < 3; i++) pw[i][0] = 1;
for (int j = 1; j < maxn; j++)
for (int i = 0; i < 3; i++)
pw[i][j] = (pw[i][j - 1] * p[i]) % mod[i];
}
void solve() {
string s;
cin >> s;
int n = s.size();
int ans = 0;
int st = 0;
ll sth[3] = {};
ll enh[3] = {};
bool ok;
for (int i = 0; i < n; i++) {
if (i >= n / 2) {
if (n % 2 == 1 || st < i) ans++;
cout << ans << endl;
return;
}
for (int j = 0; j < 3; j++) {
sth[j] = (sth[j] + pw[j][i - st] * s[i]) % mod[j];
enh[j] = (p[j] * enh[j] + s[n - i - 1]) % mod[j];
}
ok = true;
for (int j = 0; j < 3; j++) {
ok = ok && (sth[j] == enh[j]);
}
if (ok) {
ans += 2;
st = i + 1;
for (int j = 0; j < 3; j++)
sth[j] = enh[j] = 0;
}
}
}
int main() {
fast;
preprocess();
int t;
cin >> t;
while (t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23844 KB |
Output is correct |
3 |
Correct |
22 ms |
23960 KB |
Output is correct |
4 |
Correct |
23 ms |
24036 KB |
Output is correct |
5 |
Correct |
23 ms |
24036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23844 KB |
Output is correct |
3 |
Correct |
22 ms |
23960 KB |
Output is correct |
4 |
Correct |
23 ms |
24036 KB |
Output is correct |
5 |
Correct |
23 ms |
24036 KB |
Output is correct |
6 |
Correct |
24 ms |
24036 KB |
Output is correct |
7 |
Correct |
23 ms |
24044 KB |
Output is correct |
8 |
Correct |
24 ms |
24044 KB |
Output is correct |
9 |
Correct |
23 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23844 KB |
Output is correct |
3 |
Correct |
22 ms |
23960 KB |
Output is correct |
4 |
Correct |
23 ms |
24036 KB |
Output is correct |
5 |
Correct |
23 ms |
24036 KB |
Output is correct |
6 |
Correct |
24 ms |
24036 KB |
Output is correct |
7 |
Correct |
23 ms |
24044 KB |
Output is correct |
8 |
Correct |
24 ms |
24044 KB |
Output is correct |
9 |
Correct |
23 ms |
24044 KB |
Output is correct |
10 |
Correct |
27 ms |
24044 KB |
Output is correct |
11 |
Correct |
25 ms |
24044 KB |
Output is correct |
12 |
Correct |
28 ms |
24044 KB |
Output is correct |
13 |
Correct |
27 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23844 KB |
Output is correct |
3 |
Correct |
22 ms |
23960 KB |
Output is correct |
4 |
Correct |
23 ms |
24036 KB |
Output is correct |
5 |
Correct |
23 ms |
24036 KB |
Output is correct |
6 |
Correct |
24 ms |
24036 KB |
Output is correct |
7 |
Correct |
23 ms |
24044 KB |
Output is correct |
8 |
Correct |
24 ms |
24044 KB |
Output is correct |
9 |
Correct |
23 ms |
24044 KB |
Output is correct |
10 |
Correct |
27 ms |
24044 KB |
Output is correct |
11 |
Correct |
25 ms |
24044 KB |
Output is correct |
12 |
Correct |
28 ms |
24044 KB |
Output is correct |
13 |
Correct |
27 ms |
24044 KB |
Output is correct |
14 |
Correct |
455 ms |
27052 KB |
Output is correct |
15 |
Correct |
260 ms |
27052 KB |
Output is correct |
16 |
Correct |
434 ms |
27052 KB |
Output is correct |
17 |
Correct |
301 ms |
27052 KB |
Output is correct |