#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) cout << s.substr((n - 1) / 2);
else if (d2 == 1) cout << s.substr((n + 1) / 2, (n - 1) / 2);
else cout << "NOT POSSIBLE";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
6212 KB |
Output is correct |
2 |
Correct |
33 ms |
5448 KB |
Output is correct |
3 |
Correct |
36 ms |
4684 KB |
Output is correct |
4 |
Correct |
33 ms |
5336 KB |
Output is correct |
5 |
Correct |
37 ms |
6224 KB |
Output is correct |
6 |
Correct |
29 ms |
7232 KB |
Output is correct |
7 |
Incorrect |
38 ms |
5844 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |