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;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int counter[26];
int main() {
fast();
int n;
string s;
cin>>n>>s;
// for(char c:s) counter[c-'A']++;
// int odd=0;
// char index;
// for(int i=0;i<26;i++) {
// odd+=(counter[i]%2);
// if(counter[i]%2) index=i+'A';
// }
// if(odd!=1) cout<<"NOT POSSIBLE\n";
if(n%2==0) {
cout<<"NOT POSSIBLE\n";
return 0;
}
// cout<<"debug\n";
string ans1,ans2;
bool f=0;
string res1,res2;
string l=s.substr(0,n/2),r=s.substr(n/2,n/2);
f=0;
res1.clear();
res2.clear();
string _l=l+s[n/2],_r=r;
for(int i=0;i<n/2;i++) {
// cout<<_l[i]<<' '<<_r[i+f]<<'\n';
if(_l[i+f]!=_r[i]) f=1;
res1+=_l[i+f];
res2+=_r[i];
}
ans1=(res1 == res2 ? res1 : "");
f=0;
res1.clear();
res2.clear();
_l.pop_back();
_r=s[n/2]+_r;
for(int i=0;i<n/2;i++) {
// cout<<_r[i]<<' '<<_l[i+f]<<'\n';
if(_r[i]!=_l[i+f]) f=1;
res1+=_r[i];
res2+=_l[i+f];
}
ans2=(res1 == res2 ? res1 : "");
if(ans1.size() && ans2.size() && ans1!=ans2) cout<<"NOT UNIQUE\n";
else if(!ans1.size() && !ans2.size()) cout<<"NOT POSSIBLE\n";
else if(ans1.size()) cout<<ans1<<'\n';
else cout<<ans2<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |