Submission #4076

# Submission time Handle Problem Language Result Execution time Memory
4076 2013-08-31T19:33:28 Z ainta Make superpalindrome! (kriii1_M) C++
1 / 1
0 ms 1284 KB
#include<stdio.h>
#include<string.h>
char p[100010],pp[100010];
int n;
bool Next_Super(int a,int b){
	if(a==b)return true;
	int m=(a+b)>>1,i;
	bool chk;
	if(a%2==b%2){
		chk=Next_Super(a,m-1);
		if(!chk){
			for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
			p[m]='a';
			return false;
		}
		else{
			for(i=m+1;i<=b;i++){
				if(p[i]>p[a+b-i]){
					chk=false;
					break;
				}
				if(p[i]!=p[a+b-i])break;
			}
			if(i==b+1)return true;
			if(!chk){
				if(p[m]!='z')p[m]++;
				else{
					p[m-1]++;
					Next_Super(a,m-1);
					p[m]='a';
				}
			}
			for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
			return false;
		}
	}
	else{
		chk=Next_Super(a,m);
		if(!chk){
			for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
			return false;
		}
		else{
			for(i=m+1;i<=b;i++){
				if(p[i]>p[a+b-i]){
					chk=false;
					break;
				}
				if(p[i]!=p[a+b-i])break;
			}
			if(i==b+1)return true;
			if(!chk){
				p[m]++;
				Next_Super(a,m);
			}
			for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
			return false;
		}
	}
}
int main()
{
	int i;
	scanf("%s",p);
	n=strlen(p);
	for(i=0;i<n;i++)pp[i]=p[i];
	Next_Super(0,n-1);
	printf("%s\n",p);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1284 KB Output is correct
2 Correct 0 ms 1284 KB Output is correct
3 Correct 0 ms 1284 KB Output is correct
4 Correct 0 ms 1284 KB Output is correct
5 Correct 0 ms 1284 KB Output is correct
6 Correct 0 ms 1284 KB Output is correct
7 Correct 0 ms 1284 KB Output is correct
8 Correct 0 ms 1284 KB Output is correct
9 Correct 0 ms 1284 KB Output is correct
10 Correct 0 ms 1284 KB Output is correct
11 Correct 0 ms 1284 KB Output is correct
12 Correct 0 ms 1284 KB Output is correct
13 Correct 0 ms 1284 KB Output is correct
14 Correct 0 ms 1284 KB Output is correct
15 Correct 0 ms 1284 KB Output is correct
16 Correct 0 ms 1284 KB Output is correct
17 Correct 0 ms 1284 KB Output is correct
18 Correct 0 ms 1284 KB Output is correct
19 Correct 0 ms 1284 KB Output is correct
20 Correct 0 ms 1284 KB Output is correct