//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
const int maxn=1e6+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
const int pr = 637;
ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
string s ;
ll tav[maxn] ;
ll h[maxn] ;
ll L ;
ll R ;
ll sz ;
ll n ;
ll l ;
ll r ;
ll mid ;
ll b ;
ll ans ;
ll lh ;
ll rh ;
ll cnt ;
ll t;
int main()
{
int t ;
migmig;
tav[0] = 1 ;
for(int i = 1; i < maxn ; i ++ )
{
tav[i] = tav[i-1] * pr % mod ;
}
cin>> t ;
for(int i = 0 ; i < t ;i++){
ans = 0 ;
cin>>s ;
L= 0 ;
R = s.size() - 1 ;
lh = rh = 0 ;
cnt = 0 ;
for(; L < R ; L++ , R-- , cnt++){
lh = (lh * pr % mod + s[L]) % mod ;
rh = (rh + tav[cnt] * s[R] % mod ) % mod ;
if(lh == rh)
{
ans += 2 ;
lh = rh = cnt = 0 ; cnt = -1 ;
}
}
if(s.size() % 2 == 1 || lh != rh)
ans ++ ;
cout<<ans << endl ;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8172 KB |
Output is correct |
2 |
Correct |
10 ms |
8300 KB |
Output is correct |
3 |
Correct |
9 ms |
8172 KB |
Output is correct |
4 |
Correct |
10 ms |
8172 KB |
Output is correct |
5 |
Correct |
11 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8172 KB |
Output is correct |
2 |
Correct |
10 ms |
8300 KB |
Output is correct |
3 |
Correct |
9 ms |
8172 KB |
Output is correct |
4 |
Correct |
10 ms |
8172 KB |
Output is correct |
5 |
Correct |
11 ms |
8172 KB |
Output is correct |
6 |
Correct |
9 ms |
8172 KB |
Output is correct |
7 |
Correct |
10 ms |
8172 KB |
Output is correct |
8 |
Correct |
10 ms |
8172 KB |
Output is correct |
9 |
Correct |
9 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8172 KB |
Output is correct |
2 |
Correct |
10 ms |
8300 KB |
Output is correct |
3 |
Correct |
9 ms |
8172 KB |
Output is correct |
4 |
Correct |
10 ms |
8172 KB |
Output is correct |
5 |
Correct |
11 ms |
8172 KB |
Output is correct |
6 |
Correct |
9 ms |
8172 KB |
Output is correct |
7 |
Correct |
10 ms |
8172 KB |
Output is correct |
8 |
Correct |
10 ms |
8172 KB |
Output is correct |
9 |
Correct |
9 ms |
8172 KB |
Output is correct |
10 |
Correct |
11 ms |
8172 KB |
Output is correct |
11 |
Correct |
10 ms |
8172 KB |
Output is correct |
12 |
Correct |
10 ms |
8204 KB |
Output is correct |
13 |
Correct |
10 ms |
8300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8172 KB |
Output is correct |
2 |
Correct |
10 ms |
8300 KB |
Output is correct |
3 |
Correct |
9 ms |
8172 KB |
Output is correct |
4 |
Correct |
10 ms |
8172 KB |
Output is correct |
5 |
Correct |
11 ms |
8172 KB |
Output is correct |
6 |
Correct |
9 ms |
8172 KB |
Output is correct |
7 |
Correct |
10 ms |
8172 KB |
Output is correct |
8 |
Correct |
10 ms |
8172 KB |
Output is correct |
9 |
Correct |
9 ms |
8172 KB |
Output is correct |
10 |
Correct |
11 ms |
8172 KB |
Output is correct |
11 |
Correct |
10 ms |
8172 KB |
Output is correct |
12 |
Correct |
10 ms |
8204 KB |
Output is correct |
13 |
Correct |
10 ms |
8300 KB |
Output is correct |
14 |
Correct |
77 ms |
9352 KB |
Output is correct |
15 |
Correct |
48 ms |
9344 KB |
Output is correct |
16 |
Correct |
85 ms |
9344 KB |
Output is correct |
17 |
Correct |
42 ms |
9344 KB |
Output is correct |