# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3725 | waps12b | Make superpalindrome! (kriii1_M) | C++98 | 4 ms | 2216 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<string>
#include<iostream>
#include<algorithm>
using namespace std;
//s보다 사전순 같거나 앞에 있으면서 슈퍼팰린드롬
string make(string s){
//1인 경우는 볼 필요 없다.
if(s.length() == 1) return s;
int len = s.length();
bool sw = false;
for(int i=0; i< (len+1)/2;i++){
char &l = s[i];
char &r = s[len - i - 1];
if( l < r )
sw = true;
r = l;
}
if(sw){
for(int i= (len+1)/2 -1; i>=0; i--){
char &l = s[i];
char &r = s[len - i - 1];
if( l != 'z'){
l++;
r= l;
break;
}
l = r = 'a';
}
}
string ans = make(s.substr(0,len/2));
string ar = ans;
reverse(ar.begin(),ar.end());
if(len&1){
if(ans > s.substr(0,len/2))
s[(len)/2] = 'a';
return ans + s[(len)/2] + ar;
}
return ans + ar;
}
int main(){
string s;
cin >> s ;
for(int i=s.length()-1;i>=0;i--){
if(s[i] !='z'){
s[i] ++;
break;
}
s[i] = 'a';
}
cout << make(s) << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |