# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
394892 | Nicholas_Patrick | Three Friends (BOI14_friends) | C++17 | 54 ms | 7180 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>
#include <string>
using namespace std;
bool valid(string& s, string& a){
int n=a.size();
bool miss=false;
for(int i=0, j=0; i<s.size(); i++){
if(s[i]!=a[j]){
if(miss)
return false;
miss=true;
}else{
j++;
if(j==n)
j=0;
}
}
return true;
}
int main(){
int n;
string s;
cin>>n>>s;
if(~n&1){
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
n>>=1;
string a=s.substr(0, n), b=s.substr(n+1, n*2+1);
if(valid(s, a)){
if(valid(s, b)){
if(a==b){
cout<<a<<endl;
}else{
cout<<"NOT UNIQUE"<<endl;
}
}else{
cout<<a<<endl;
}
}else{
if(valid(s, b)){
cout<<b<<endl;
}else{
cout<<"NOT POSSIBLE"<<endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |