# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
447384 | fuad27 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 80 ms | 11796 KiB |
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<iostream>
using namespace std;
#define int long long
#define mod (long long)(1e17-3)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) {
string s;
cin >> s;
int ans = 0, n = s.length();
long long hash1 = 0, hash2 = 0, pw = 1, cnt = 0, j = n;
for(int i = 0;i<n/2;i++) {
hash1 = (26*hash1%mod + (s[i] - 'a'))%mod;
hash2 = (hash2+((s[n-i-1]-'a'))*pw%mod)%mod;
if(hash1 == hash2){
hash1 = 0;
hash2 = 0;
ans+=2;
pw = 1;
j = i;
}
else pw=26*pw%mod;
}
if(j!=(n/2)-1 or n%2)ans++;
cout<<ans<<'\n';
}
}
Compilation message (stderr)
# | 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... |