# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398780 | almothana05 | Three Friends (BOI14_friends) | C++14 | 0 ms | 0 KiB |
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<iostream>
using namespace std;
vector<int>re(50 , 0);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int menge , numm , nummer , erge = INT_MAX;
bool nu1 = 0 , kann1 = 1 , nu2 = 0 , kann2 = 1;
string s , s1 ,s2;
cin >> menge >> s;
if(menge % 2 == 0){
cout << "NOT POSSIBLE";
return 0;
}
for(int i = 0 ; i <= menge /2 ; i++){
s1 += s[i];
}
for(int i = menge/2 ; i < menge ; i++){
s2 += s[i];
}
//cout << s1 << ' ' << s2 << "\n";
for(int i = 0 , j = 1; i < s1.size() ; i++){
if(s1[i] == s2[j]){
//cout << s1[i] << ' ' << s2[j] << "\n";
j++;
}
else{
if(j > 1 && s1[i] == s2[j - 1] ){
nu1 = 1;
}
}
if(i == s1.size() - 1 && j != s2.size() ){
// cout << i << ' ' << j << "\n";
kann1 = 0;
}
}
s1.pop_back();
for(int i = 0 , j = 0 ; i < s2.size() ; i++){
if(j == s1.size()){
if(s1[j-1] == s2[i] ){
nu2 = 1;
}
}
if(s2[i] == s1[j]){
j++;
}
else{
if(j > 0 && s2[i] == s1[j - 1]){
nu2 = 1;
}
}
if(i == s2.size() - 1 && j != s1.size()){
kann2 = 0;
}
}
if(kann1 == 1 ){
if(kann2 == 1 || nu1 == 1){
cout << "NOT UNIQUE";
}
else{
for(int i = 1 ; i < s2.size() ; i++){
cout << s2[i];
}
}
}
else if(kann2 == 1){
if(nu2 == 1){
cout << "NOT UNIQUE";
}
else{
cout << s1;
}
}
else{
cout <<" NOT POSSIBLE";
}
//cout << kann1 << ' ' << nu1 << "\n" << kann2 << ' ' << nu2<<"\n";
return 0;
}