# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42641 | XmtosX | 세 명의 친구들 (BOI14_friends) | C++14 | 108 ms | 7844 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 <bits/stdc++.h>
using namespace std;
int n,cnt,cnt1;
string s,s1,s2,ans;
bool yes;
int main()
{
cin >>n>>s;
if (n%2==0)
{
cout <<"NOT POSSIBLE";
return 0;
}
s1=s.substr(n/2+1,n/2);
s2=s.substr(0,n/2+1);
for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
{
if (i==s1.size())
{
if (s2[j]==s2[j-1])
{
cout <<"NOT UNIQUE";
return 0;
}
cnt++;
break;
}
if (s1[i]!=s2[j])
{
if (i!=j)
break;
if (s2[j-1]==s2[j]||s2[j+1]==s2[j])
yes=true;
i--;
}
}
if (!cnt)
yes=false;
else if (yes)
{
cout <<"NOT UNIQUE";
return 0;
}
else
ans=s1;
yes=false;
s1=s.substr(0,n/2);
s2=s.substr(n/2,n/2+1);
if (s1==ans)
goto ss;
for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
{
if (i==s1.size())
{
if (s2[j]==s2[j-1])
{
cout <<"NOT UNIQUE";
return 0;
}
cnt1++;
break;
}
if (s1[i]!=s2[j])
{
if (i!=j)
break;
if (s2[j-1]==s2[j]||s2[j+1]==s2[j])
yes=true;
i--;
}
}
ss:
if (!cnt1)
yes=false;
else
ans=s1;
if (!cnt&&!cnt1)
cout <<"NOT POSSIBLE";
else if (yes||cnt+cnt1>1)
cout <<"NOT UNIQUE";
else
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |