#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,cnt_67,cnt_97,pow_97[1000005],pow_67[1000005],MOD=1e9+7,it;
ll cnt2_67,cnt2_97,cnt,type=-1;
string s;
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
pow_97[0]=1;
pow_67[0]=1;
for(int i=1;i<=1000000;i++)
{
pow_97[i]=pow_97[i-1]*97;
pow_97[i]%=MOD;
pow_67[i]=pow_67[i-1]*67;
pow_67[i]%=MOD;
}
cin >> t;
while(t--)
{
cin >> s;
cnt_97=0;
cnt_67=0;
cnt2_97=0;
cnt2_67=0;
it=0;
cnt=0;
type=-1;
for(int i=0;i<s.size()/2;i++)
{
cnt_67+=pow_67[it]*s[i];
cnt_67%=MOD;
cnt_97+=pow_97[it]*s[i];
cnt_97%=MOD;
cnt2_67*=67;
cnt2_67%=MOD;
cnt2_67+=s[s.size()-1-i];
cnt2_67%=MOD;
cnt2_97*=97;
cnt2_97%=MOD;
cnt2_97+=s[s.size()-1-i];
cnt2_97%=MOD;
++it;
if(cnt2_67==cnt_67&&cnt2_97==cnt_97)
{
//printf("%d\n",i);
cnt_67=0;
cnt2_67=0;
cnt_97=0;
cnt2_97=0;
cnt+=2;
if(s.size()%2==0&&i==s.size()/2-1)
{
type=0;
}
it=0;
}
}
++cnt;
if(type==0)--cnt;
printf("%lld\n",cnt);
}
}
Compilation message
palindromic.cpp: In function 'int main()':
palindromic.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<s.size()/2;i++)
| ~^~~~~~~~~~~
palindromic.cpp:53:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if(s.size()%2==0&&i==s.size()/2-1)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15956 KB |
Output is correct |
2 |
Correct |
17 ms |
15972 KB |
Output is correct |
3 |
Correct |
16 ms |
15932 KB |
Output is correct |
4 |
Correct |
17 ms |
15868 KB |
Output is correct |
5 |
Correct |
16 ms |
15956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15956 KB |
Output is correct |
2 |
Correct |
17 ms |
15972 KB |
Output is correct |
3 |
Correct |
16 ms |
15932 KB |
Output is correct |
4 |
Correct |
17 ms |
15868 KB |
Output is correct |
5 |
Correct |
16 ms |
15956 KB |
Output is correct |
6 |
Correct |
17 ms |
15928 KB |
Output is correct |
7 |
Correct |
17 ms |
15884 KB |
Output is correct |
8 |
Correct |
16 ms |
15928 KB |
Output is correct |
9 |
Correct |
17 ms |
15972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15956 KB |
Output is correct |
2 |
Correct |
17 ms |
15972 KB |
Output is correct |
3 |
Correct |
16 ms |
15932 KB |
Output is correct |
4 |
Correct |
17 ms |
15868 KB |
Output is correct |
5 |
Correct |
16 ms |
15956 KB |
Output is correct |
6 |
Correct |
17 ms |
15928 KB |
Output is correct |
7 |
Correct |
17 ms |
15884 KB |
Output is correct |
8 |
Correct |
16 ms |
15928 KB |
Output is correct |
9 |
Correct |
17 ms |
15972 KB |
Output is correct |
10 |
Correct |
19 ms |
16072 KB |
Output is correct |
11 |
Correct |
19 ms |
15972 KB |
Output is correct |
12 |
Correct |
18 ms |
16088 KB |
Output is correct |
13 |
Correct |
18 ms |
15988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15956 KB |
Output is correct |
2 |
Correct |
17 ms |
15972 KB |
Output is correct |
3 |
Correct |
16 ms |
15932 KB |
Output is correct |
4 |
Correct |
17 ms |
15868 KB |
Output is correct |
5 |
Correct |
16 ms |
15956 KB |
Output is correct |
6 |
Correct |
17 ms |
15928 KB |
Output is correct |
7 |
Correct |
17 ms |
15884 KB |
Output is correct |
8 |
Correct |
16 ms |
15928 KB |
Output is correct |
9 |
Correct |
17 ms |
15972 KB |
Output is correct |
10 |
Correct |
19 ms |
16072 KB |
Output is correct |
11 |
Correct |
19 ms |
15972 KB |
Output is correct |
12 |
Correct |
18 ms |
16088 KB |
Output is correct |
13 |
Correct |
18 ms |
15988 KB |
Output is correct |
14 |
Correct |
172 ms |
26780 KB |
Output is correct |
15 |
Correct |
103 ms |
22164 KB |
Output is correct |
16 |
Correct |
172 ms |
26212 KB |
Output is correct |
17 |
Correct |
94 ms |
21704 KB |
Output is correct |