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;
int32_t main() {
int n;
string s;
cin >> n >> s;
if ((n % 2) == 0) {
cout << "NOT POSSIBLE\n";
return 0;
}
int tam = (n - 1)/2;
int pos = 0;
// test possibility 1
string ans1 = "";
int curr = 0;
int skipped = 0;
for (int i = tam; i < n; i++) {
if ((curr < tam) && (s[curr] == s[i])) {
curr++;
} else {
skipped++;
}
if (skipped == 2) break;
}
if (skipped == 1) {
for (int i = 0; i < tam; i++) ans1 += s[i];
pos++;
}
// test possibility 2
string ans2 = "";
curr = tam + 1;
skipped = 0;
for (int i = 0; i <= tam; i++) {
if ((curr < n) && (s[curr] == s[i])) {
curr++;
} else {
skipped++;
}
if (skipped == 2) break;
}
if (skipped == 1) {
for (int i = tam + 1; i < n; i++) ans2 += s[i];
pos++;
}
// gonow
if (pos == 0) {
cout << "NOT POSSIBLE\n";
} else if ((pos == 2) && (ans1 != ans2)) {
cout << "NOT UNIQUE\n";
} else if (ans1.empty()) {
cout << ans2 << "\n";
} else {
cout << ans1 << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |