Submission #395575

#TimeUsernameProblemLanguageResultExecution timeMemory
395575AlmaThree Friends (BOI14_friends)C++14
0 / 100
21 ms8100 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n; cin >> n;
    string s; cin >> s;

    if (n % 2 == 0) {
        cout << "NOT POSSIBLE\n";
        return 0;
    }
    // string a = s.substr(0, n/2);
    // string b = s.substr((n+1)/2, n/2);

    // left:
    bool left = true, l = true;
    int a = 0, b = n/2;
    string leftPart = "";
    while (a < n/2 && b < n) {
        if (s[a] != s[b]) {
            if (l) {
                b++;
                l = false;
            } else {
                left = false;
            }
        }
        leftPart += s[a];
        a++; b++;
    }

    // right:
    bool right = true, r = true;
    int c = (n+1)/2, d = 0;
    string rightPart = "";
    while (c < n && d < (n+1)/2) {
        if (s[c] != s[d]) {
            if (r) {
                d++;
                r = false;
            } else {
                right = false;
            }
        }
        rightPart += s[c];
        c++; d++;
    }

    if (left && right) {
        cout << "NOT UNIQUE\n";
    } else if (left) {
        cout << leftPart << '\n';
    } else if (right) {
        cout << rightPart << '\n';
    } else {
        cout << "NOT POSSIBLE\n";
    }

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