#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'){
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2088 KB |
Output is correct |
2 |
Correct |
4 ms |
2208 KB |
Output is correct |
3 |
Correct |
4 ms |
2112 KB |
Output is correct |
4 |
Correct |
4 ms |
2216 KB |
Output is correct |
5 |
Correct |
4 ms |
2096 KB |
Output is correct |
6 |
Incorrect |
0 ms |
1672 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |