제출 #392757

#제출 시각아이디문제언어결과실행 시간메모리
392757Alma세 명의 친구들 (BOI14_friends)C++14
0 / 100
10 ms4328 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int N; cin >> N;
    string S; cin >> S;

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

    int extraChar, 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];

    // first char
    if (left == right) numSubstr++;

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

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

    if (numSubstr == 0) {
        cout << "NOT POSSIBLE\n";
    } else if (numSubstr > 1) {
        cout << "NOT UNIQUE\n";
    } else {
        int i = 0;
        while (i < N/2) {
            if (i != extraChar) cout << S[i];
            i++;
        }
        if (extraChar <= N/2) cout << S[i];
        cout << '\n';
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int main()':
friends.cpp:57:9: warning: 'extraChar' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         if (extraChar <= N/2) cout << S[i];
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...