#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
const long long MOD = 1e9 + 7, base = 29;
string st;
int n;
long long Hash[N], POW[N];
void InitHash() {
Hash[0] = 0;
FOR(i, 1, n) Hash[i] = (Hash[i - 1] * base + st[i] - 'a') % MOD;
}
long long GetHash(int i, int j) {
return (Hash[j] - Hash[i - 1] * POW[j - i + 1] % MOD + MOD * MOD) % MOD;
}
int Go(int l, int r) {
//DEBUG(l);DEBUG(r);
if (l == r) return 1;
if (l > r) return 0;
FOR(len, 1, r - l + 1) {
if (l + len - 1 >= r - len + 1) break;
//DEBUG(len);
//DEBUG(GetHash(l, l + len - 1));
//DEBUG(GetHash(r - len + 1, r));
if (GetHash(l, l + len - 1) == GetHash(r - len + 1, r)) return 2 + Go(l + len, r - len);
}
return 1;
}
void solve() {
cin >> st;
n = st.size();
st = '~' + st;
InitHash();
cout << Go(1, n) << '\n';
}
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
double stime = clock();
#else
//freopen(taskname".inp","r",stdin);
//freopen(taskname".out","w",stdout);
#endif //NERO
IO;
POW[0] = 1;
FOR(i, 1, N - 1) POW[i] = POW[i - 1] * base % MOD;
int test;
cin >> test;
while (test--) solve();
#ifdef NERO
double etime = clock();
cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // NERO
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8220 KB |
Output is correct |
4 |
Correct |
13 ms |
8236 KB |
Output is correct |
5 |
Correct |
14 ms |
8236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8220 KB |
Output is correct |
4 |
Correct |
13 ms |
8236 KB |
Output is correct |
5 |
Correct |
14 ms |
8236 KB |
Output is correct |
6 |
Correct |
13 ms |
8308 KB |
Output is correct |
7 |
Correct |
13 ms |
8320 KB |
Output is correct |
8 |
Correct |
13 ms |
8320 KB |
Output is correct |
9 |
Correct |
13 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8220 KB |
Output is correct |
4 |
Correct |
13 ms |
8236 KB |
Output is correct |
5 |
Correct |
14 ms |
8236 KB |
Output is correct |
6 |
Correct |
13 ms |
8308 KB |
Output is correct |
7 |
Correct |
13 ms |
8320 KB |
Output is correct |
8 |
Correct |
13 ms |
8320 KB |
Output is correct |
9 |
Correct |
13 ms |
8320 KB |
Output is correct |
10 |
Correct |
15 ms |
8448 KB |
Output is correct |
11 |
Correct |
14 ms |
8528 KB |
Output is correct |
12 |
Correct |
15 ms |
8528 KB |
Output is correct |
13 |
Correct |
15 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
8184 KB |
Output is correct |
2 |
Correct |
13 ms |
8184 KB |
Output is correct |
3 |
Correct |
13 ms |
8220 KB |
Output is correct |
4 |
Correct |
13 ms |
8236 KB |
Output is correct |
5 |
Correct |
14 ms |
8236 KB |
Output is correct |
6 |
Correct |
13 ms |
8308 KB |
Output is correct |
7 |
Correct |
13 ms |
8320 KB |
Output is correct |
8 |
Correct |
13 ms |
8320 KB |
Output is correct |
9 |
Correct |
13 ms |
8320 KB |
Output is correct |
10 |
Correct |
15 ms |
8448 KB |
Output is correct |
11 |
Correct |
14 ms |
8528 KB |
Output is correct |
12 |
Correct |
15 ms |
8528 KB |
Output is correct |
13 |
Correct |
15 ms |
8528 KB |
Output is correct |
14 |
Correct |
165 ms |
18220 KB |
Output is correct |
15 |
Correct |
99 ms |
18220 KB |
Output is correct |
16 |
Correct |
170 ms |
19828 KB |
Output is correct |
17 |
Correct |
99 ms |
19828 KB |
Output is correct |