답안 #149192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149192 2019-09-01T05:56:00 Z 티셔츠 콜렉터(#3632, yoni, jisunchae, jsg1504) HicCup (FXCUP4_hiccup) C++17
0 / 100
5 ms 384 KB
#include "hiccup.h"
int max(int A, int B) {
    if(A>B) return A;
    else return B;
}

int maximumHiccup (int* levelCountArray, int level) {
    if (levelCountArray[level] == 0) {
        return 0;
    } else {
        int childHiccup = maximumHiccup(levelCountArray, level + 1);
        if (childHiccup % 2 == 0) {
            return max(childHiccup, levelCountArray[level]);
        } else {
            return -1;
        }
    }
    
}

int HicCup(std::string S) {
    int N = S.size();
    int levelArray[N] = {-1};
    int level = 1;
    int firstCharacterIndex = 0;
    char previousCharacter = ' ';
    
    // 첫번째 캐릭터 찾는 루프
    for (int index = 0; index < N; index++) {
        if (S[index] != '!') {
            previousCharacter = S[index];
            levelArray[index] = 1;
            firstCharacterIndex = index;
            break;
        }
        levelArray[index] = -1;
    }
    
    // 나머지 루프
    for (int index = firstCharacterIndex + 1; index < N; index++) {
        if (S[index] == '!') {
            levelArray[index] = -1;
            continue;
        }
        if (previousCharacter != S[index]) {
            levelArray[index] = level;
        }
        if (previousCharacter == S[index]) {
            if (previousCharacter == 'H') levelArray[index] = ++level;
            if (previousCharacter == 'C') levelArray[index] = --level;
        }
        previousCharacter = S[index];
    }
    
    int levelCountArray[N] = {0};

    for (int i= 0; i < N ; i++){
        if (levelArray[i] != -1) levelCountArray[levelArray[i]]++;
    }
    
    
    int max = maximumHiccup(levelCountArray, 1);
    if (max % 2 == 0) {
        return max / 2;
    } else {
        return -1;
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -