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;
const int MAX_N = 2e6 + 5;
char U[MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N >> (U + 1);
if(N % 2 == 0) {
cout << "NOT POSSIBLE";
return 0;
}
int M = N / 2;
int l = 1, r = M + 1, cnt = 0;
bool frnt = false, bck = false;
while(l <= M and r <= N) {
if(U[l] == U[r]) {
l++, r++;
}
else {
cnt++;
r++;
}
}
if(cnt <= 1) {
frnt = true;
}
l = 1, r = M + 2, cnt = 0;
while(l <= M + 1 and r <= N) {
if(U[l] == U[r]) {
l++, r++;
}
else {
cnt++;
l++;
}
}
if(cnt <= 1) {
bck = true;
}
if(frnt == true and bck == true) {
cnt = 0;
for(int i = 1; i <= M; i++) {
if(U[i] == U[M + 1 + i]) {
cnt++;
}
}
if(cnt == M) {
for(int i = 1; i <= M; i++) {
cout << U[i];
}
}
else {
cout << "NOT UNIQUE";
}
}
else if(frnt == true) {
for(int i = 1; i <= M; i++) {
cout << U[i];
}
}
else if(bck == true) {
for(int i = M + 2; i <= N; i++) {
cout << U[i];
}
}
else {
cout << "NOT POSSIBLE";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |