#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<
template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
template<int SZ> struct rabinKarp {
const ll mods[3] = {1000000007, 999119999, 1000992299};
ll p[3][SZ];
ll h[3][SZ];
const ll base = 1000696969;
rabinKarp() {}
void build(string a) {
M00(i, 3) {
p[i][0] = 1;
h[i][0] = (int)a[0];
MOO(j, 1, (int)a.length()) {
p[i][j] = (p[i][j-1] * mods[i]) % base;
h[i][j] = (h[i][j-1] * mods[i] + (int)a[j]) % base;
}
}
}
tuple<ll, ll, ll> hsh(int a, int b) {
if(a == 0) return make_tuple(h[0][b], h[1][b], h[2][b]);
tuple<ll, ll, ll> ans;
get<0>(ans) = (((h[0][b] - h[0][a-1]*p[0][b-a+1]) % base) + base) % base;
get<1>(ans) = (((h[1][b] - h[1][a-1]*p[1][b-a+1]) % base) + base) % base;
get<2>(ans) = (((h[2][b] - h[2][a-1]*p[2][b-a+1]) % base) + base) % base;
return ans;
}
};
const int MAX_N = 1000010;
rabinKarp<MAX_N> rk;
int main() { FAST
int t; cin >> t;
while(t--) {
string s; cin >> s;
rk.build(s);
int last = 0;
int cnt = 0;
M00(i, sz(s)/2) {
if(rk.hsh(last, i) == rk.hsh(sz(s)-1-i, sz(s)-1-last)) {
cnt++;
last = i+1;
}
}
cout << 2*cnt+1 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |