This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define task "paltext"
#define fi first
#define se second
#define int long long
#define ii pair<int,int>
#define ld double
#define mp make_pair
#define lg2 21
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define fii fi.fi
#define fis fi.se
#define sfi se.fi
#define see se.se
#define base 31
int dx[]={0LL,0LL,1,-1,1,1,-1,-1};
int dy[]={1,-1,0LL,0LL,1,-1,1,-1};
const int maxn=1e6+1;
const int maxa=5*maxn;
const int mod=998244353;
const int maxi=1000;
string s;
int n,pw[maxn],hs[maxn];
int geth(int l,int r)
{
return (hs[r]-hs[l-1]*pw[r-l+1]+mod*mod)%mod;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);}
int t;
cin>>t;
while(t--){
cin>>s;
n=s.size();
s=' '+s;
pw[0]=1;
for(int i=1;i<=n;i++)
{
pw[i]=(pw[i-1]*base)%mod;
}
for(int i=1;i<=n;i++)
{
hs[i]=(hs[i-1]*base+s[i]-'a'+1)%mod;
}
int last=1;
int ans=0;
for(int i=1;i<=n;i++)
{
if(geth(last,i)==geth(n-i+1,n-last+1))
{
ans++;
last=i+1;
}
}
cout<<ans<<'\n';
}
}
Compilation message (stderr)
palindromic.cpp: In function 'int main()':
palindromic.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen(task".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |