제출 #584469

#제출 시각아이디문제언어결과실행 시간메모리
584469Blagoj세 명의 친구들 (BOI14_friends)C++14
100 / 100
18 ms18120 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int sz;
    cin >> sz;
    string u;
    cin >> u;
    if (sz % 2 == 0)
    {
        cout << "NOT POSSIBLE";
        return 0;
    }
    int result = 0;
    string kraj;
    set<string>s;
    string a1 = u.substr(0, sz / 2), a2 = u.substr(sz / 2 + 1);
    if (a1 == a2)
    {
        s.insert(a1);
        result++;
        kraj = a1;
    }
    a1 = u.substr(1, sz / 2), a2 = u.substr(sz / 2 + 1);
    if (a1 == a2 && s.count(a1) == 0)
    {
        s.insert(a1);
        result++;
        if (result > 1)
        {
            cout << "NOT UNIQUE";
            return 0;
        }
        kraj = a1;
    }
    a1 = u.substr(0, sz / 2), a2 = u.substr(sz / 2, sz / 2);
    if (a1 == a2 && s.count(a1) == 0)
    {
        s.insert(a1);
        result++;
        if (result > 1)
        {
            cout << "NOT UNIQUE";
            return 0;
        }
        kraj = a1;
    }
    a1 = u.substr(0, sz / 2 + 1), a2 = u.substr(sz / 2 + 1);
    for (int i = 0; i < sz / 2; i++)
    {
        if (a1[i] != a2[i])
        {
            string l = u.substr(0, i), r = u.substr(i + 1);
            string temp = l + r;
            string temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
            if (temp1 == temp2 && s.count(temp1) == 0)
            {
                s.insert (temp1);
                result++;
                if (result > 1)
                {
                    cout << "NOT UNIQUE";
                    return 0;
                }
                kraj = temp1;
            }
            if (sz / 2 + i + 1 < sz)
            {
                r = u.substr(sz / 2 + i + 1);
            }
            l = u.substr(0, sz / 2 + i);
            temp = l + r;
            temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
            if (temp1 == temp2 && s.count(temp1) == 0)
            {
                s.insert(temp1);
                result++;
                if(result > 1)
                {
                    cout << "NOT UNIQUE";
                    return 0;
                }
                kraj = temp1;
            }
            break;
        }
    }
    a1 = u.substr(0, sz / 2), a2 = u.substr(sz / 2);
    for (int i = 0; i < sz / 2; i++)
    {
        if (a1[i] != a2[i])
        {
            string l = u.substr(0, i), r = u.substr(i + 1);
            string temp = l + r;
            string temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
            if (temp1 == temp2 && s.count(temp1) == 0)
            {
                s.insert(temp1);
                result++;
                if (result > 1)
                {
                    cout << "NOT UNIQUE";
                    return 0;
                }
                kraj = temp1;
            }
            if (sz / 2 + i + 1 < sz)
            {
                r = u.substr(sz / 2 + i + 1);
            }
            l = u.substr(0, sz / 2 + i);
            temp = l + r;
            temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
            if (temp1 == temp2 && s.count(temp1) == 0)
            {
                s.insert(temp1);
                result++;
                if(result > 1)
                {
                    cout << "NOT UNIQUE";
                    return 0;
                }
                kraj = temp1;
            }
            break;
        }
    }
    if (result == 0)
    {
        cout << "NOT POSSIBLE";
        return 0;
    }
    cout << kraj;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...