# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3904 | cki86201 | Make superpalindrome! (kriii1_M) | C++98 | 0 ms | 1672 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<stdio.h>
#include<string.h>
int len;
int str[100000]={0};
char s[100001]={0};
char ans[100001]={0};
void f(int a,int b){
if(a==b) return;
int i;
f(a,(a+b-1)/2);
for(i=b;i>(a+b)/2;i--){
str[i]=str[b-i+a];
}
}
int main()
{
int i,ch=0;
scanf("%s",&s);
len=strlen(s);
for(i=0;i<len;i++) str[i]=i;
f(0,len-1);
for(i=0;i<len;i++){
if(i==str[i]) ans[i]=s[i];
}
for(i=0;i<len;i++){
if(ans[str[i]]!=s[i]){
ch=1;
break;
}
}
if(ch==0){
for(i=len-1;i>=0;i--){
if(i==str[i] && ans[str[i]]!='z'){
ans[str[i]]++;
for(i++;i<len;i++)
if(i==str[i]) ans[i]='a';
break;
}
}
}
else{
for(i=0;i<len;i++){
if(ans[str[i]]<s[i]){
for(;i>=0;i--){
if(i==str[i] && ans[str[i]]!='z'){
ans[str[i]]++;
break;
}
}
for(i++;i<len;i++){
if(i==str[i])
ans[str[i]]='a';
}
break;
}
else if(ans[str[i]]>s[i]){
for(i++;i<len;i++){
if(i==str[i])
ans[str[i]]='a';
}
}
}
}
for(i=0;i<len;i++) printf("%c",ans[str[i]]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |