# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72888 | Vardanyan | Three Friends (BOI14_friends) | C++14 | 154 ms | 16052 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.
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
bool check(string a,string b){
if(a.length()<b.length()) swap(a,b);
int i = 0;
int j = 0;
bool f = false;
while(i<a.length()){
if(a[i]!=b[j] && f) return false;
if(a[i]!=b[j]){
f = true;
i++;
continue;
}
i++;
j++;
}
return true;
}
int main()
{
int n;
string s;
cin>>n>>s;
if(n%2 == 0){
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
string s1;
for(int i = 0;i<n/2;i++) s1+=s[i];
string s2;
for(int i = n/2+1;i<n;i++) s2+=s[i];
string s3;
for(int i = 0;i<=n/2;i++) s3+=s[i];
string s4;
for(int i = n/2;i<n;i++) s4+=s[i];
int c = check(s1,s4)+check(s2,s3);
if(c == 0){
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
if(c == 1 || s1 == s2){
if(check(s1,s4)) cout<<s1<<endl;
else cout<<s2<<endl;
return 0;
}
cout<<"NOT UNIQUE"<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |