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; cin >> n; string s; cin >> s;
if (n % 2 == 0) { cout << "NOT POSSIBLE"; return 0; }
int mp1[26]{}, mp2[26]{}; int l = (n - 1) / 2;
for (int i = 0; i < n; i++) {
int chr = (s[i] - 'A');
if (i < l) mp1[chr]++;
else mp2[chr]++;
}
int d1 = 0; for (int i = 0; i < 26; i++) d1 += abs(mp1[i] - mp2[i]);
fill(mp1, mp1 + 26, 0); fill(mp2, mp2 + 26, 0); l = (n + 1) / 2;
for (int i = 0; i < n; i++) {
int chr = (s[i] - 'A');
if (i < l) mp1[chr]++;
else mp2[chr]++;
}
int d2 = 0; for (int i = 0; i < 26; i++) d2 += abs(mp1[i] - mp2[i]);
if (d1 == 1 && d2 == 1) cout << "NOT UNIQUE";
else if (d1 == 1) {
int diff = 0, a = 0, b = l - 1;
while (a < l - 1) {
if (s[a] != s[b]) {
diff++, b++;
if (diff == 2) break;
} a++, b++;
}
if (diff == 2) cout << "NOT POSSIBLE";
else cout << s.substr(0, (n - 1) / 2);
} else if (d2 == 1) {
int diff = 0, a = 0, b = l;
while (b < n) {
if (s[a] != s[b]) {
diff++, a++;
if (diff == 2) break;
} a++, b++;
}
if (diff == 2) cout << "NOT POSSIBLE";
else cout << s.substr((n + 1) / 2, (n - 1) / 2);
}
else cout << "NOT POSSIBLE";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |