# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243214 | kimbj0709 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 84 ms | 20708 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 <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000009
#define maxn 1000050
#define po 179
vector<int> powers(maxn,1);
void find(){
string input;
cin >> input;
int sum1 = 0;
int sum2 = 0;
int ans = 0;
int cnt = -1;
int currcnt = 0;
for(int i=0;i<input.length()/2;i++){
sum1 += powers[currcnt]*(input.at(i)-'a');
sum2 *= po;
sum1 %= mod;
sum2 %= mod;
sum2 += (input.at(input.length()-1-i)-'a');
currcnt++;
sum2 %= mod;
if(sum1==sum2){
ans += 2;
sum1 = 0;
sum2 = 0;
cnt = i;
currcnt = 0;
}
}
if((cnt+1)*2==input.length()){
}
else{
ans++;
}
cout << ans << "\n";
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int no_of_input;
cin >> no_of_input;
for(int i=1;i<powers.size();i++){
powers[i] = powers[i-1]*po;
powers[i] %= mod;
}
for(int i=0;i<no_of_input;i++){
find();
}
}
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... |