# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017405 | 2024-07-09T07:46:32 Z | cnn008 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 0 ms | 348 KB |
#include "bits/stdc++.h" using namespace std; #ifdef N_N_C #include "debug.h" #else #define cebug(...) "Arya" #endif #define ll long long const int N=1e6+5; const int mod=1e9+7; const int base=31; int n,ans,h[N],pw[N]; string s; int get(int l, int r){ return (h[r]-(h[l-1]*pw[r-l+1])%mod+mod)%mod; } void sol(){ ans=0; cin>>s; n=(int)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++) h[i]=(h[i-1]*base+s[i]-'a')%mod; int l=1,r=n; while(l<=r){ int _l=l,_r=r,f=0; while(_l<_r){ if(get(l,_l++)==get(_r--,r)){ cebug(s,l,_l,_r,r); ans+=2; f=1; break; } } if(!f){ ans++; break; } l=_l; r=_r; } cout<<ans<<"\n"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); int tt=1; cin>>tt; while(tt--){ sol(); } cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |