#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
int t, p = 47;
cin>>t;
vector<ll> pw(1000001);
pw[0] = 1;
for (int i = 1; i <= 1000001; i++){
pw[i] = (pw[i - 1] * p) % mod;
}
for (int it = 0; it < t; it++){
string s;
cin>>s;
int l = 0, lind = -1, r = s.size() - 1;
ll lhash = 0, rhash = 0, c = 0;
while (l < r){
lind++;
lhash += s[l] * pw[lind];
lhash %= mod;
rhash = rhash * p + s[r];
rhash %= mod;
if (lhash == rhash){
c += 2;
lhash = 0;
rhash = 0;
lind = -1;
}
l++;
r--;
}
if (l == r || lhash != 0 || rhash != 0){
c++;
}
cout<<c<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
7 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
7 ms |
8028 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8280 KB |
Output is correct |
8 |
Correct |
7 ms |
8284 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
7 ms |
8028 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8280 KB |
Output is correct |
8 |
Correct |
7 ms |
8284 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
9 ms |
8284 KB |
Output is correct |
11 |
Correct |
8 ms |
8360 KB |
Output is correct |
12 |
Correct |
8 ms |
8292 KB |
Output is correct |
13 |
Correct |
8 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8284 KB |
Output is correct |
2 |
Correct |
8 ms |
8284 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
7 ms |
8028 KB |
Output is correct |
5 |
Correct |
7 ms |
8028 KB |
Output is correct |
6 |
Correct |
7 ms |
8284 KB |
Output is correct |
7 |
Correct |
7 ms |
8280 KB |
Output is correct |
8 |
Correct |
7 ms |
8284 KB |
Output is correct |
9 |
Correct |
7 ms |
8284 KB |
Output is correct |
10 |
Correct |
9 ms |
8284 KB |
Output is correct |
11 |
Correct |
8 ms |
8360 KB |
Output is correct |
12 |
Correct |
8 ms |
8292 KB |
Output is correct |
13 |
Correct |
8 ms |
8284 KB |
Output is correct |
14 |
Correct |
169 ms |
20076 KB |
Output is correct |
15 |
Correct |
92 ms |
15040 KB |
Output is correct |
16 |
Correct |
156 ms |
19164 KB |
Output is correct |
17 |
Correct |
92 ms |
14812 KB |
Output is correct |