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;
int main(){
int N;
cin >> N;
string U;
cin >> U;
if (N % 2 == 0){
cout << "NOT POSSIBLE" << endl;
} else {
int L1 = 0;
while (L1 < (N - 1) / 2){
if (U[L1] == U[L1 + (N + 1) / 2]){
L1++;
} else {
break;
}
}
int R1 = (N - 1) / 2;
while (R1 >= 0){
if (U[R1] == U[R1 + (N - 1) / 2]){
R1--;
} else {
break;
}
}
int L2 = (N - 1) / 2;
while (L2 < N){
if (U[L2] == U[L2 - (N - 1) / 2]){
L2++;
} else {
break;
}
}
int R2 = N - 1;
while (R2 >= (N + 1) / 2){
if (U[R2] == U[R2 - (N + 1) / 2]){
R2--;
} else {
break;
}
}
if (L1 >= R1 && L2 >= R2){
if (U.substr(0, (N - 1) / 2) == U.substr((N + 1) / 2)){
cout << U.substr(0, (N - 1) / 2) << endl;
} else {
cout << "NOT UNIQUE" << endl;
}
} else if (L1 >= R1){
cout << U.substr((N + 1) / 2) << endl;
} else if (L2 >= R2){
cout << U.substr(0, (N - 1) / 2) << endl;
} else {
cout << "NOT POSSIBLE" << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |