Submission #934228

#TimeUsernameProblemLanguageResultExecution timeMemory
934228Faisal_SaqibPalindromic Partitions (CEOI17_palindromic)C++17
15 / 100
1 ms348 KiB
#include <iostream> using namespace std; #define int long long #define ll long long const ll base=717; const ll mod=1e9+9; const int N=110; ll n,pre[N],pw[N]; void Hash(string& s) { n=(int)s.size(); pre[0]=0; for(int i=1;i<=n;i++) { pre[i]=(pre[i-1]*base)%mod; pre[i]+=(s[i-1]-'a'); pre[i]%=mod; } pw[0]=1; for(int i=1;i<=n;i++) pw[i]=(pw[i-1]*base)%mod; } // (l,r) // s[r] // s[l]*(r-l) + .. s[r] // s[l-1] // s[l-1] int get(int l,int r)//inclusive 1-based indexing { return (pre[r]+mod-((pre[l-1]*pw[r-l+1])%mod))%mod; } void solve() { string s; cin>>s; Hash(s); int l=0; int r=n+1; int cnt=0; while((l+1)<r) { int sl=l; int sr=r; for(int len=1;len<=(r-l-1);len++) { if(get(l+1,l+len)==get(r-len,r-1)) { cnt++; cnt+=((l+1!=(r-len)) or ((l+len)!=(r-1))); l+=len; r-=len; break; } } } cout<<cnt<<endl; // both endpoints are exclusive (l,r) } signed main() { int t; cin>>t; while(t--) { solve(); } }

Compilation message (stderr)

palindromic.cpp: In function 'void solve()':
palindromic.cpp:43:7: warning: unused variable 'sl' [-Wunused-variable]
   43 |   int sl=l;
      |       ^~
palindromic.cpp:44:7: warning: unused variable 'sr' [-Wunused-variable]
   44 |   int sr=r;
      |       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...