Submission #3592

# Submission time Handle Problem Language Result Execution time Memory
3592 2013-08-31T06:46:28 Z Apple_Cplus Make superpalindrome! (kriii1_M) C++
0 / 1
0 ms 1924 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 
 



char a[100005];
string A;

string Get(int x){
	string r;
	bool same=1;
	string mid="";
	for(int s=0,e=x-1;s<=e;s++,e--){
		if(s==e){
			if(same==0){
				mid+='a';
			}else{
				mid+=A[s];
			}
		}else{
			if(same==0){
				r+='a';
			}else{
				char t=max(A[s],A[e]);
				r+=t;
				if(t>A[s])same=0;
			}
		}
	}
	string r2=r;reverse(ALL(r2));
	return r+mid+r2;
}
void UP(string &A){
	int n=A.size();
	
	int s,e;
	s=n/2;e=n/2;
	if(A.size()%2==0)e++;
	
	A[s]++;
	

	for(s;s>=0;s--,e++){
		if(A[s]>'z'){
			A[s]='a';
			A[e]='a';

			A[s-1]++;
			A[e+1]++;
		}else break;
	}

}
int main(){
	scanf("%s",&a);
	A=a;
	int n=A.size();
	string L=Get(n/2);
	string L1=A.substr(0,n/2);
	
	string mid="";
	string R2="";

	if(A.size()%2){
		R2=A.substr(n/2+1);
		mid+=A[n/2];
	}else{
		R2=A.substr(n/2);
	}

	bool up=1;
	if(L==L1)up=0;

	if(up){
		if(mid.size())mid="a";
		cout<<L<<mid<<L<<endl;
	}else{
		if(R2<=L){
			cout<<L<<mid<<L;
		}else{
			UP(L);
			if(mid.size())mid="a";
			cout<<L<<mid<<L;
		}
	}

}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1924 KB Output isn't correct
2 Halted 0 ms 0 KB -