답안 #392932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392932 2021-04-22T10:19:53 Z Alma 세 명의 친구들 (BOI14_friends) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

bool equal (int N,  string & S, int extraChar) {
    string a = "", b = "";
    for (int i = 0; i < N; i++) {

        if (i == extraChar) continue;

        if ((int)a.size() < N/2) {
            a += S[i];
        } else {
            b += S[i];
        }
    }
    return a == b;
}

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

    int N; // cin >> N;
    string S; cin >> S;
    N = (int)S.size();

    if (N % 2 == 0) {
        cout << "NOT POSSIBLE\n";
        return 0;
    }

    int extraChar = 0, numSubstr = 0;
    char left = ' ', right = ' ';

    for (int i = 1; i <= N/2; i++)
        left ^= S[i];
    for (int i = N/2 + 1; i < N; i++)
        right ^= S[i];

    if (left == right && equal(N, S, extraChar)) numSubstr++;

    for (int currChar = 1; currChar <= N/2; currChar++) {
        left ^= S[currChar];
        left ^= S[currChar - 1];
        if (left == right) {
            extraChar = currChar;
            if (equal(N, S, extraChar)) numSubstr++;

            if (numSubstr > 1) {
                cout << "NOT UNIQUE\n";
                return 0;
            }
        }
    }

    for (int currChar = N/2 + 1; currChar < N; currChar++) {
        right ^= S[currChar];
        right ^= S[currChar - 1];
        if (left == right) {
            extraChar = currChar;
            if (equal(N, S, extraChar)) numSubstr++;

            if (numSubstr > 1) {
                cout << "NOT UNIQUE\n";
                return 0;
            }
        }
    }

    if (numSubstr == 0) {
        cout << "NOT POSSIBLE\n";
    } else if (numSubstr > 1) {
        cout << "NOT UNIQUE\n";
    } else {

        string a = "", b = "";
        for (int i = 0; i < N; i++) {

            if (i == extraChar) continue;

            if ((int)a.size() < N/2) {
                a += S[i];
            } else {
                b += S[i];
            }
        }
        if (a == b) cout << a << '\n';
        else cout << "NOT POSSIBLE\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -