#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int MAXN = 1000010, MOD = 1e9+9, P = 31;
int n;
string s;
ll pref[MAXN], power[MAXN];
ll value(int i, int j) {
if (i == 0) return pref[j];
return ((pref[j]-(pref[i-1]*power[j-i+1])%MOD)%MOD+MOD)%MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
power[0] = 1;
for (int i = 1; i < MAXN; ++i) {
power[i] = power[i-1] * P;
power[i] %= MOD;
}
int tests; cin >> tests;
while (tests--) {
cin >> s;
n = s.size();
pref[0] = s[0]-'a'+1;
for (int i = 1; i < n; ++i) {
pref[i] = (pref[i-1]*P)%MOD + (s[i]-'a'+1);
pref[i] %= MOD;
}
int lx = 0, rx = n-1, j = n-1;
int ans = 0;
for (int i = 0; i < n; ++i) {
if (j <= i) break;
if (value(lx, i) == value(j, rx)) {
ans += 2;
lx = i+1, rx = j-1;
}
--j;
}
if (lx <= rx) ++ans;
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
8 ms |
8160 KB |
Output is correct |
4 |
Correct |
8 ms |
8148 KB |
Output is correct |
5 |
Correct |
8 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
8 ms |
8160 KB |
Output is correct |
4 |
Correct |
8 ms |
8148 KB |
Output is correct |
5 |
Correct |
8 ms |
8148 KB |
Output is correct |
6 |
Correct |
9 ms |
8164 KB |
Output is correct |
7 |
Correct |
8 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
8 ms |
8160 KB |
Output is correct |
4 |
Correct |
8 ms |
8148 KB |
Output is correct |
5 |
Correct |
8 ms |
8148 KB |
Output is correct |
6 |
Correct |
9 ms |
8164 KB |
Output is correct |
7 |
Correct |
8 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8148 KB |
Output is correct |
10 |
Correct |
9 ms |
8276 KB |
Output is correct |
11 |
Correct |
9 ms |
8276 KB |
Output is correct |
12 |
Correct |
10 ms |
8308 KB |
Output is correct |
13 |
Correct |
9 ms |
8312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
8 ms |
8160 KB |
Output is correct |
4 |
Correct |
8 ms |
8148 KB |
Output is correct |
5 |
Correct |
8 ms |
8148 KB |
Output is correct |
6 |
Correct |
9 ms |
8164 KB |
Output is correct |
7 |
Correct |
8 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8148 KB |
Output is correct |
10 |
Correct |
9 ms |
8276 KB |
Output is correct |
11 |
Correct |
9 ms |
8276 KB |
Output is correct |
12 |
Correct |
10 ms |
8308 KB |
Output is correct |
13 |
Correct |
9 ms |
8312 KB |
Output is correct |
14 |
Correct |
163 ms |
25684 KB |
Output is correct |
15 |
Correct |
91 ms |
22276 KB |
Output is correct |
16 |
Correct |
162 ms |
25596 KB |
Output is correct |
17 |
Correct |
91 ms |
17992 KB |
Output is correct |