Submission #398811

#TimeUsernameProblemLanguageResultExecution timeMemory
398811ALI_SQUAREDThree Friends (BOI14_friends)C++14
0 / 100
133 ms15244 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;

    string s, a = "", b = "", c = "", d = "", answer1 = "", answer2 = "";
    cin >> s;

    if (n % 2 == 0){cout << "Not Possible"; return 0;}

    for (int i = 0; i < n; i++){
        if (i < n/2) a += s[i], c += s[i];
        else if (i == n/2) b += s[i], c += s[i];
        else b += s[i], d += s[i];
    }

    string x = "", y = "";
    int add = 0;

    for (int i = 0; i < n/2; i++){
        if (a[i] == b[i+add]) x += a[i], y += b[i+add];
        else x += a[i], y += b[i+1], add = 1;
    }

    if (x == y) answer1 = x;

    x = "", y = "";
    add = 0;

    for (int i = 0; i < n/2; i++){
        if (d[i] == c[i+add]) x += d[i], y += c[i+add];
        else x += d[i], y += c[i+1], add = 1;
    }

    if (x == y) answer2 = x;

    //cout << "answer2: " << answer2 << "\n";

    if (answer1.size() && answer2.size() && answer1 != answer2) cout << "NOT UNIQUE";
    else if (!answer1.size() && !answer2.size()) cout << "NOT POSSIBLE";
    else if (answer1.size()) cout << answer1;
    else cout << answer2;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...