#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_97+=pow_97[it]*s[i];
cnt2_67*=67;
cnt2_67+=s[s.size()-1-i];
cnt2_97*=97;
cnt2_97+=s[s.size()-1-i];
++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:47:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(s.size()%2==0&&i==s.size()/2-1)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
15920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
15920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
15920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
15920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |