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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n;
string u,a,b;
bool pre[2000005],suf[2000005];
bool isa, isb;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> u;
if(n%2==0){
cout << "NOT POSSIBLE" << "\n";
return 0;
}
n /= 2;
for(int i=0;i<n;i++){
a += u[i];
}
for(int i=n+1;i<n*2+1;i++){
b += u[i];
}
if(a==b){
cout << a << "\n";
return 0;
}
for(int i=0;i<n;i++){
if(i==0){
if(u[i]==b[i]){
pre[i] = true;
}
else{
pre[i] = false;
}
}
else{
if(u[i]==b[i] and pre[i-1]){
pre[i] = true;
}
else{
pre[i] = false;
}
}
}
for(int i=n;i>0;i--){
if(i==n){
if(u[i]==b[i-1]){
suf[i] = true;
}
else{
suf[i] = false;
}
}
else{
if(u[i]==b[i-1] and suf[i+1]){
suf[i] = true;
}
else{
suf[i] = false;
}
}
}
if(pre[n-1] or suf[1]){
isa = true;
}
else{
for(int i=0;i<n-1;i++){
if(pre[i] and suf[i+2]){
isa = true;
break;
}
}
}
for(int i=n;i<2*n;i++){
if(i==n){
if(u[i]==a[i-n]){
pre[i] = true;
}
else{
pre[i] = false;
}
}
else{
if(u[i]==a[i-n] and pre[i-1]){
pre[i] = true;
}
else{
pre[i] = false;
}
}
}
for(int i=2*n;i>n;i--){
if(i==2*n){
if(u[i]==a[i-n-1]){
suf[i] = true;
}
else{
suf[i] = false;
}
}
else{
if(u[i]==a[i-n-1] and suf[i+1]){
suf[i] = true;
}
else{
suf[i] = false;
}
}
}
if(pre[2*n-1] or suf[n+1]){
isb = true;
}
else{
for(int i=n;i<2*n-1;i++){
if(pre[i] and suf[i+2]){
isb = true;
break;
}
}
}
if(isa and isb){
cout << "NOT UNIQUE" << "\n";
}
else{
if(isa){
cout << b << "\n";
}
else if(isb){
cout << a << "\n";
}
else{
cout << "NOT POSSIBLE" << "\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |