제출 #395578

#제출 시각아이디문제언어결과실행 시간메모리
395578AlmaThree Friends (BOI14_friends)C++14
0 / 100
21 ms6132 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;
    }

    // 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) {
        if (leftPart == rightPart) cout << leftPart << '\n';
        else 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...