# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21996 | gs14004 | Make superpalindrome! (kriii1_M) | C++11 | 6 ms | 3048 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;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
string rv(string s){
reverse(s.begin(), s.end());
return s;
}
bool is_super(string s){
if(s.size() <= 1) return 1;
string w = s.substr(0, s.size() / 2);
return is_super(w) && (w + s.substr(s.size() / 2, s.size() % 2) + rv(w)) == s;
}
string solve(string s){
if(s.size() == 1){
s[0]++;
return s;
}
string t = s.substr(0, s.size() / 2);
string ans = t + s.substr(s.size() / 2, s.size() % 2) + rv(t);
if(is_super(t) && ans > s) return ans;
if(is_super(t) && s.size() % 2 == 1 && s[s.size()/2] < 'z'){
ans[s.size()/2]++;
return ans;
}
t = solve(t);
if(s.size() % 2 == 0) return t + rv(t);
else return t + "a" + rv(t);
}
int main(){
string s;
cin >> s;
cout << solve(s);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |