#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
const int P = 1e9 + 11;
const int Q = 4001;
const int MAXN = 1e6+5;
int T, N;
string S;
int F[MAXN];
int solve(int s, int e) {
//cout << "solve " << s << " " << e << endl;
if (s > e) return 0;
int h1 = 0, h2 = 0;
for (int l = 0; s+l < e-l; ++l) {
h1 = (((ll)h1 * Q % P) + (S[s+l]-'a')) % P;
h2 = ((ll)h2 + (((ll)(S[e-l]-'a')*F[l]) % P)) % P;
if (h1 == h2) return solve(s+l+1, e-l-1) + 2;
}
return 1;
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
F[0] = 1;
FOR(i,1,MAXN-1) F[i] = (ll)F[i-1] * Q % P;
cin >> T;
while(T--){
cin >> S;
N = S.length();
cout << solve(0,N-1) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4216 KB |
Output is correct |
2 |
Correct |
11 ms |
4216 KB |
Output is correct |
3 |
Correct |
12 ms |
4088 KB |
Output is correct |
4 |
Correct |
12 ms |
4216 KB |
Output is correct |
5 |
Correct |
12 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4216 KB |
Output is correct |
2 |
Correct |
11 ms |
4216 KB |
Output is correct |
3 |
Correct |
12 ms |
4088 KB |
Output is correct |
4 |
Correct |
12 ms |
4216 KB |
Output is correct |
5 |
Correct |
12 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
12 ms |
4316 KB |
Output is correct |
8 |
Correct |
13 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4216 KB |
Output is correct |
2 |
Correct |
11 ms |
4216 KB |
Output is correct |
3 |
Correct |
12 ms |
4088 KB |
Output is correct |
4 |
Correct |
12 ms |
4216 KB |
Output is correct |
5 |
Correct |
12 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
12 ms |
4316 KB |
Output is correct |
8 |
Correct |
13 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
10 |
Correct |
11 ms |
4344 KB |
Output is correct |
11 |
Correct |
12 ms |
4344 KB |
Output is correct |
12 |
Correct |
12 ms |
4344 KB |
Output is correct |
13 |
Correct |
12 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4216 KB |
Output is correct |
2 |
Correct |
11 ms |
4216 KB |
Output is correct |
3 |
Correct |
12 ms |
4088 KB |
Output is correct |
4 |
Correct |
12 ms |
4216 KB |
Output is correct |
5 |
Correct |
12 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4216 KB |
Output is correct |
7 |
Correct |
12 ms |
4316 KB |
Output is correct |
8 |
Correct |
13 ms |
4216 KB |
Output is correct |
9 |
Correct |
12 ms |
4216 KB |
Output is correct |
10 |
Correct |
11 ms |
4344 KB |
Output is correct |
11 |
Correct |
12 ms |
4344 KB |
Output is correct |
12 |
Correct |
12 ms |
4344 KB |
Output is correct |
13 |
Correct |
12 ms |
4344 KB |
Output is correct |
14 |
Correct |
86 ms |
15072 KB |
Output is correct |
15 |
Correct |
52 ms |
10512 KB |
Output is correct |
16 |
Correct |
86 ms |
14616 KB |
Output is correct |
17 |
Correct |
46 ms |
10004 KB |
Output is correct |