#include <bits/stdc++.h>
using namespace std;
#define SZ(s) (int)s.size()
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
string s;
cin >> n >> s;
if(n % 2 == 0) {
cout << "NOT POSSIBLE";
return 0;
}
bool tr = 0, tr1 = 0;
vector <int> a(n+1,0);
int k = 0, x = (n/2);
string s1 = "", s2 = "";
for(int i = 0; i < x; i++){
s1 += s[i];
}
for(int i = x+1; i < n; i++){
s2 += s[i];
}
for(int i = 0; i < x; i++){
a[i] = (s[i] == s[i+x+1]);
k += a[i];
}
if(k == x) tr = 1;
for(int i = 0; i < x; i++){
k -= a[i];
a[i] = (s[i] == s[i+x]);
k += a[i];
if(k == x) tr = 1;
}
k = 0;
for(int i = n-1; i > x; i--){
a[i] = (s[i] == s[i-x-1]);
k += a[i];
}
if(k == x) tr1 = 1;
for(int i = n-1; i > x; i--){
k -= a[i];
a[i] = (s[i] == s[i-x]);
k += a[i];
if(k == x) tr1 = 1;
}
if(tr == tr1){
if(tr == 0){
cout << "NOT POSSIBLE";
}
else {
if(s1 == s2) cout << s1;
else cout << "NOT UNIQUE";
}
return 0;
}
if(tr1 == 1) cout << s2;
else cout << s1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |