Submission #42640

#TimeUsernameProblemLanguageResultExecution timeMemory
42640XmtosXThree Friends (BOI14_friends)C++14
0 / 100
91 ms9548 KiB
#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);
    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--;
        }
    }
    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)

friends.cpp: In function 'int main()':
friends.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
                       ^
friends.cpp:16:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
                                     ^
friends.cpp:18:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i==s1.size())
              ^
friends.cpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
                       ^
friends.cpp:49:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0,j=0;i<=s1.size()||j<=s2.size();i++,j++)
                                     ^
friends.cpp:51:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i==s1.size())
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...