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;
U = "$" + U;
if(n % 2 == 0){
cout << "NOT POSSIBLE" << '\n';
return 0;
}
string Front , Back;
for(int i = 1;i <= n / 2;i ++){
Front += U[i];
}
for(int i = n / 2 + 2;i <= n;i ++){
Back += U[i];
}
int t = 1 , cnt_front = 0;
for(int i = n / 2 + 1;i <= n && t <= n / 2;i ++){
if(U[i] == U[t]){
++t;
continue;
}
++cnt_front;
}
cnt_front += (t != n / 2 + 1) * 2;
int cnt_back = 0;
t = n;
for(int i = n / 2 + 1;i >= 1 && t > n / 2 + 1;i --){
if(U[i] == U[t]){
--t;
continue;
}
++cnt_back;
}
cnt_back += (t != n / 2 + 1) * 2;
if(cnt_front < 2 && cnt_back < 2 && Back != Front){
printf("%s" , "NOT UNIQUE");
return 0;
}
if(cnt_front < 2){
printf("%s" , Front.c_str());
return 0;
}
if(cnt_back < 2){
printf("%s" , Back.c_str());
return 0;
}
printf("%s" , "NOT POSSIBLE");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |