# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
939137 | vjudge1 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 1 ms | 348 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 ff first
#define ss second
#define all(a) a.begin(), a.end()
#define int long long
/*
4
bonobo
deleted
racecar
racecars
*/
void solve(){
string s; cin >> s;
int n = s.size();
deque<char> dq;
for(int i = 0;i < n; i++) dq.push_back(s[i]);
int ans = 0;
while(true){
int left = dq.size()-1;
int idx = -1, suf = 1;
int len = -1;
for(int j = dq.size() - 1; j >= 0; j--, left--, suf++){
if(suf > left) break;
int ok = 1;
for(int i = 0; i + j < dq.size(); i++){
if(dq[i] != dq[i+j]){
ok = 0;
break;
}
}
if(ok){
len = suf;
idx = j;
}
}
if(idx == -1){
ans++;
break;
}
while(len--){
dq.pop_back();
dq.pop_front();
}
ans+= 2;
if(dq.empty()) break;
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tt; cin >> tt;
while(tt--){
solve();
cout << '\n';
}
return 0;
}
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... |