#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e6+5;
char A[N];
pii d[N], iden(131, 133);
pii add(pii a, pii b) { return pii(a.x + b.x, a.y + b.y); }
pii mul(pii a, pii b) { return pii(a.x * b.x, a.y * b.y); }
void solve() {
scanf("%s", A);
int n = strlen(A), cnt = 0;
pii lhs, rhs;
for(int i = 0, p = 0; i < n; ++i, ++p) {
lhs = add(pii(A[i], A[i]), mul(iden, lhs));
rhs = add(rhs, mul(pii(A[n-i-1], A[n-i-1]), d[p]));
if(lhs == rhs) cnt++, p = -1, lhs = rhs = pii(0, 0);
}
printf("%d\n", cnt);
}
int main() {
d[0] = pii(1, 1);
for(int i = 1; i < N; ++i) d[i] = mul(d[i-1], iden);
int T; scanf("%d", &T);
while(T--) solve();
}
Compilation message
palindromic.cpp: In function 'void solve()':
palindromic.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", A);
~~~~~^~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:30:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int T; scanf("%d", &T);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8232 KB |
Output is correct |
3 |
Correct |
9 ms |
8420 KB |
Output is correct |
4 |
Correct |
9 ms |
8460 KB |
Output is correct |
5 |
Correct |
9 ms |
8460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8232 KB |
Output is correct |
3 |
Correct |
9 ms |
8420 KB |
Output is correct |
4 |
Correct |
9 ms |
8460 KB |
Output is correct |
5 |
Correct |
9 ms |
8460 KB |
Output is correct |
6 |
Correct |
8 ms |
8460 KB |
Output is correct |
7 |
Correct |
9 ms |
8572 KB |
Output is correct |
8 |
Correct |
10 ms |
8572 KB |
Output is correct |
9 |
Correct |
10 ms |
8572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8232 KB |
Output is correct |
3 |
Correct |
9 ms |
8420 KB |
Output is correct |
4 |
Correct |
9 ms |
8460 KB |
Output is correct |
5 |
Correct |
9 ms |
8460 KB |
Output is correct |
6 |
Correct |
8 ms |
8460 KB |
Output is correct |
7 |
Correct |
9 ms |
8572 KB |
Output is correct |
8 |
Correct |
10 ms |
8572 KB |
Output is correct |
9 |
Correct |
10 ms |
8572 KB |
Output is correct |
10 |
Correct |
9 ms |
8640 KB |
Output is correct |
11 |
Correct |
9 ms |
8640 KB |
Output is correct |
12 |
Correct |
10 ms |
8684 KB |
Output is correct |
13 |
Correct |
11 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8232 KB |
Output is correct |
3 |
Correct |
9 ms |
8420 KB |
Output is correct |
4 |
Correct |
9 ms |
8460 KB |
Output is correct |
5 |
Correct |
9 ms |
8460 KB |
Output is correct |
6 |
Correct |
8 ms |
8460 KB |
Output is correct |
7 |
Correct |
9 ms |
8572 KB |
Output is correct |
8 |
Correct |
10 ms |
8572 KB |
Output is correct |
9 |
Correct |
10 ms |
8572 KB |
Output is correct |
10 |
Correct |
9 ms |
8640 KB |
Output is correct |
11 |
Correct |
9 ms |
8640 KB |
Output is correct |
12 |
Correct |
10 ms |
8684 KB |
Output is correct |
13 |
Correct |
11 ms |
8780 KB |
Output is correct |
14 |
Correct |
91 ms |
19764 KB |
Output is correct |
15 |
Correct |
45 ms |
24748 KB |
Output is correct |
16 |
Correct |
92 ms |
34052 KB |
Output is correct |
17 |
Correct |
56 ms |
38824 KB |
Output is correct |