# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
707800 | 2023-03-10T07:21:56 Z | guagua0407 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 316 ms | 28632 KB |
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=1e6+5; ll p=27; ll mod=(1ll<<61)-1; ll powv[mxn]; ll hashv[mxn]; void pre(){ powv[0]=1; for(int i=1;i<mxn;i++){ powv[i]=((__int128)powv[i-1]*p)%mod; } } void genhash(string str){ for(int i=1;i<=str.length();i++){ hashv[i]=((__int128)hashv[i-1]*p%mod+str[i-1]-'a'+1)%mod; } } ll cal(int l,int r){ ll ans=(hashv[r]-(__int128)hashv[l-1]*powv[r-l+1]%mod)%mod; if(ans<0) ans+=mod; return ans; } void solve(){ string str; cin>>str; int n=str.length(); genhash(str); int l=1; int ans=0; while(l<=n/2){ int r=l; bool tf=false; while(r<=n/2){ if(cal(l,r)==cal(n-l+1-(r-l+1)+1,n-l+1)){ tf=true; break; } r++; } if(tf){ ans++; l=r+1; } else{ break; } } ans*=2; if(l!=n/2+1 or n&1) ans++; cout<<ans<<'\n'; } int main() {_ //setIO("wayne"); pre(); int t; cin>>t; while(t--){ solve(); } return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8148 KB | Output is correct |
2 | Correct | 9 ms | 8148 KB | Output is correct |
3 | Correct | 8 ms | 8148 KB | Output is correct |
4 | Correct | 8 ms | 8148 KB | Output is correct |
5 | Correct | 9 ms | 8148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8148 KB | Output is correct |
2 | Correct | 9 ms | 8148 KB | Output is correct |
3 | Correct | 8 ms | 8148 KB | Output is correct |
4 | Correct | 8 ms | 8148 KB | Output is correct |
5 | Correct | 9 ms | 8148 KB | Output is correct |
6 | Correct | 8 ms | 8148 KB | Output is correct |
7 | Correct | 9 ms | 8160 KB | Output is correct |
8 | Correct | 9 ms | 8152 KB | Output is correct |
9 | Correct | 9 ms | 8148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8148 KB | Output is correct |
2 | Correct | 9 ms | 8148 KB | Output is correct |
3 | Correct | 8 ms | 8148 KB | Output is correct |
4 | Correct | 8 ms | 8148 KB | Output is correct |
5 | Correct | 9 ms | 8148 KB | Output is correct |
6 | Correct | 8 ms | 8148 KB | Output is correct |
7 | Correct | 9 ms | 8160 KB | Output is correct |
8 | Correct | 9 ms | 8152 KB | Output is correct |
9 | Correct | 9 ms | 8148 KB | Output is correct |
10 | Correct | 11 ms | 8264 KB | Output is correct |
11 | Correct | 10 ms | 8292 KB | Output is correct |
12 | Correct | 11 ms | 8276 KB | Output is correct |
13 | Correct | 11 ms | 8276 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8148 KB | Output is correct |
2 | Correct | 9 ms | 8148 KB | Output is correct |
3 | Correct | 8 ms | 8148 KB | Output is correct |
4 | Correct | 8 ms | 8148 KB | Output is correct |
5 | Correct | 9 ms | 8148 KB | Output is correct |
6 | Correct | 8 ms | 8148 KB | Output is correct |
7 | Correct | 9 ms | 8160 KB | Output is correct |
8 | Correct | 9 ms | 8152 KB | Output is correct |
9 | Correct | 9 ms | 8148 KB | Output is correct |
10 | Correct | 11 ms | 8264 KB | Output is correct |
11 | Correct | 10 ms | 8292 KB | Output is correct |
12 | Correct | 11 ms | 8276 KB | Output is correct |
13 | Correct | 11 ms | 8276 KB | Output is correct |
14 | Correct | 272 ms | 28632 KB | Output is correct |
15 | Correct | 149 ms | 23336 KB | Output is correct |
16 | Correct | 316 ms | 27572 KB | Output is correct |
17 | Correct | 125 ms | 18924 KB | Output is correct |