Submission #939169

#TimeUsernameProblemLanguageResultExecution timeMemory
939169vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
6 ms8028 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=1e6+5,mod=1e9+7,tt=13; int pw[N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int t; cin>>t; pw[0]=1; for(int i=1;i<N;i++){ pw[i]=pw[i-1]*tt; pw[i]%=mod; } while(t--){ string s; cin>>s; s=" "+s; vector <int> h(s.size()); for(int i=1;i<s.size();i++){ h[i]=h[i-1]*tt+(s[i]-'a'+1); h[i]%=mod; } int st1=1,end2=s.size()-1; int end1=1,st2=s.size()-1; int h1=0,h2=0; int ans=0; while(end1<st2){ h1=(h[end1]-h[st1-1]*pw[end1-st1+1])%mod; h2=(h[end2]-h[st2-1]*pw[end2-st2+1])%mod; if(h1==h2){ end1++; st1=end1; st2--; end2=st2; ans+=2; } else{ st2--; end1++; } } if(st1<=end2)ans++; cout<<ans<<"\n"; } } /* */

Compilation message (stderr)

palindromic.cpp: In function 'int main()':
palindromic.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int i=1;i<s.size();i++){
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...