Submission #584368

#TimeUsernameProblemLanguageResultExecution timeMemory
584368BlagojThree Friends (BOI14_friends)C++14
0 / 100
68 ms15976 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;
    }
    map<char, int>mp;
    for (int i = 0; i < sz; i++)
    {
        mp[u[i]]++;
    }
    int result = 0;
    string kraj;
    set<string>s;
    string a1, a2;
    a1 = u.substr(1, sz / 2), a2 = u.substr(sz / 2);
    if (a1 == a2)
    {
        s.insert(a1);
        kraj = a1;
        result++;
    }
    else
    {
        for (int i = 0; i < sz / 2; i++)
        {
            if (a1[i] != a2[i])
            {
                string temp = u.substr(0, i) + u.substr(i + 1), temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
                if (temp1 == temp2 && s.count(temp1) == 0)
                {
                    s.insert(temp1);
                    result++;
                    kraj = temp1;
                    if (result > 1)
                    {
                        cout << "NOT UNIQUE";
                        return 0;
                    }
                }
                temp = u.substr(0, i + sz / 2) + u.substr(i + sz / 2);
                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, sz / 2);
    if (a1 == a2)
    {
        s.insert(a1);
        kraj = a1;
        result++;
        if (result > 1)
        {
            cout << "NOT UNIQUE";
            return 0;
        }
    }
    else
    {
        for (int i = 0; i < sz / 2; i++)
        {
            if (a1[i] != a2[i])
            {
                string temp = u.substr(0, i) + u.substr(i + 1), temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
                if (temp1 == temp2 && s.count(temp1) == 0)
                {
                    s.insert(temp1);
                    result++;
                    kraj = temp1;
                    if (result > 1)
                    {
                        cout << "NOT UNIQUE";
                        return 0;
                    }
                }
                temp = u.substr(0, i + sz / 2) + u.substr(i + sz / 2);
                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 + 1);
    if (a1 == a2)
    {
        s.insert(a1);
        kraj = a1;
        result++;
        if (result > 1)
        {
            cout << "NOT UNIQUE";
            return 0;
        }
    }
    else
    {
        for (int i = 0; i < sz / 2; i++)
        {
            if (a1[i] != a2[i])
            {
                string temp = u.substr(0, i) + u.substr(i + 1), temp1 = temp.substr(0, sz / 2), temp2 = temp.substr(sz / 2);
                if (temp1 == temp2 && s.count(temp1) == 0)
                {
                    s.insert(temp1);
                    result++;
                    kraj = temp1;
                    if (result > 1)
                    {
                        cout << "NOT UNIQUE";
                        return 0;
                    }
                }
                temp = u.substr(0, i + sz / 2) + u.substr(i + sz / 2);
                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...