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>
#include <math.h>
//in the name of god,aka allah
//**gray sety orz**
#pragma GCC optimize("unroll-loops")
using namespace std;
#define pi pair<long long , long long>
#define pii pair<long long , pair<long long , long long>>
const int maxm =1e6 + 5;
long long aval = 27;
const long long mod = 1e9 + 7 ;
typedef long long ll;
ll l,r,mid;
ll n,m;
ll dis[maxm] , sum[maxm];
bool isval(int mid){
//cout << mid <<" " << mid*mid-mid <<endl;
if (((mid-1)*mid)/2 < m) return 0;
return 1;
}
int darage[maxm] , ss , mm;
queue<int> q;
vector<pi> g[maxm] , z[maxm];
ll sath[maxm];
bool vis[maxm] , gos[maxm];
int pedaret[maxm];
ll get_par(ll v){
if (pedaret[v]==v) return v;
return pedaret[v] = get_par(pedaret[v]);
}
void merge(ll r , ll q){
if (get_par(r)!=get_par(q))l+=max(darage[r],darage[q])*1ll*sath[r]*1ll*sath[q];
r = get_par(r) , q = get_par(q);
if (r!=q){
if (sath[r]<sath[q]) swap(r,q);
pedaret[q] = r;
sath[r] += sath[q];
}
return ;
}
ll pars1[maxm] , pars2[maxm];
vector<ll> se[maxm];
set<pi> st;
int rp[maxm];
pi w[maxm];
int dp[maxm];
//ll rw[maxm][maxm];
map<ll,ll> mp;
void solve(){
string s;
cin >>s;
l = 0 , r = 0 , mid = 0 , ss = 1;
for (int i=0; i<=s.size()/2-1; i++){
l*=aval , l%=mod;
l+=(s[i]-'a'+1);
l%=mod;
r+=(((s[s.size()-1-i]-'a')+1)*ss);
r%=mod;
ss*=aval;
ss%=mod;
if (l==r) mid+=2 , ss = 1 , l = 0 , r = 0;
}
if (l!=0 || s.size()%2) mid++;
cout<<mid<<endl;
}
int main() {
ios::sync_with_stdio (0), cin.tie (0), cout.tie (0);
int t;
cin >>t;
while (t--){
solve();
}
}
Compilation message (stderr)
palindromic.cpp: In function 'void solve()':
palindromic.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i=0; i<=s.size()/2-1; i++){
| ~^~~~~~~~~~~~~~
# | 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... |