#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
ll pw(ll a,ll b) {
ll ans=1;
ll now=a;
while (b) {
if (b&1) {
ans*=now;
ans%=P;
}
now*=now;
now%=P;
b>>=1;
}
return ans;
}
struct Hash {
string s;
ll n;
ll x;
vector<ll> pre,inv;
Hash(string _s,int x):s(_s),n(s.size()-1),x(x) {
pre.resize(n+1);
inv.resize(n+1);
ll now=1;
inv[0]=1;
inv[1]=pw(x,P-2);
for (int i=1;i<=n;i++) {
now = (now*x)%P;
inv[i]=inv[i-1]*inv[1];
inv[i]%=P;
pre[i]=pre[i-1]+s[i]*now;
pre[i]%=P;
}
}
ll query(ll a,ll b) {
return (pre[b]-pre[a-1]+P)%P*inv[a-1]%P;
}
};
void solve() {
string s;
cin>>s;
int n = s.size();
s = '-'+s;
Hash h(s,83);
int now=1;
int ans=0;
for (int i=1;2*i<=n;i++) {
if (h.query(now,i)==h.query(n-i+1,n-now+1)) {
ans+=2;
now=i+1;
}
}
cout<<ans+1<<"\n";
}
int main() {
speed;
int t;
cin>>t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |