# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154440 | brcode | Three Friends (BOI14_friends) | C++14 | 142 ms | 9164 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;
string res;
string res2;
bool ans1 = true;
bool ans2 = true;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int mid = (s.length()+1)/2;
int sz = (s.length()-1)/2;
s='#'+s;
int temp = mid+1;
bool ok = false;
int j = 1;
int cnt = 1;
while(cnt<=sz){
if(s[j]!=s[temp]){
if(ok){
ans1= false;
break;
}else{
ok = true;
j++;
}
}else{
temp++;
j++;
cnt++;
}
}
ok = false;
temp= mid;
j=1;
cnt = 1;
while(cnt<=sz){
// cout<<s[j]<<" "<<s[temp]<<endl;
if(s[j]!=s[temp]){
if(ok){
ans2 = false;
break;
}else{
ok = true;
temp++;
}
}else{
temp++;
j++;
cnt++;
}
}
// cout<<ans1<<" "<<ans2<<endl;
if((!ans1 && !ans2)||s.length()%2 == 1){
cout<<"NOT POSSIBLE"<<endl;
}else if(!ans2){
for(int i=mid+1;i<s.length();i++){
res+=s[i];
}
cout<<res<<endl;
}else if(!ans1){
for(int i=1;i<=sz;i++){
res+=s[i];
}
cout<<res<<endl;
}else{
// cout<<res<<" "<<res2<<endl;
res="";
res2="";
for(int i=mid+1;i<s.length();i++){
// cout<<s[i]<<endl;
res+=s[i];
}
for(int i=1;i<=sz;i++){
res2+=s[i];
}
if(res == res2){
cout<<res<<endl;
}else{
cout<<"NOT UNIQUE"<<endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |