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;
int main(){
int n; cin >> n;
string s; cin >> s;
if(!(n&1)){
cout << "NOT POSSIBLE\n";
return 0;
}
vector<int> am(26,0);
for(int i = 0; i < n; ++i){
am[s[i]-'A']++;
}
int tot = 0;
char c = '?';
for(int i = 0; i < 26; ++i){
if(am[i]&1){tot++;c = 'A'+i;}
}
if(tot > 1){cout << "NOT POSSIBLE\n"; return 0;}
int ans = 0;
string ori;
string s1, s2;
for(int i = 0; i < n; ++i){
if(s[i] == c){
if(i >= n/2){
s1 = s.substr(0,n/2);
}
else{
s1 = s.substr(0,i);
s1+=s.substr(i+1, n/2-i);
}
if(i <= n/2){
s2 = s.substr(n/2+1,n/2);
}
else{
s2 = s.substr(n/2,i-n/2);
s2+=s.substr(i+1,n/2-(i-n/2));
}
if(s1 == s2){ans++;ori = s1;}
}
if(ans > 1){cout << "NOT UNIQUE\n";return 0;}
}
if(!ans){cout << "NOT POSSIBLE\n"; return 0;}
cout << ori << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |