답안 #26702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26702 2017-07-05T04:37:35 Z sgc109 질문 (CEOI14_question_grader) C++11
60 / 100
1831 ms 25672 KB
int encode (int n, int x, int y) {
    int ok = 0;
    int pos = -1;
    int sum1 = 0, sum2 = 0;
    for(int i = 0 ; i < 10; i++){
        int a = (x & (1<<i)) != 0;
        int b = (y & (1<<i)) != 0;
        sum1 += a;
        sum2 += b;
        if(a > b){
            ok = 1;
            pos = i;
            break;
        }
    }
    if(pos != -1) return pos+1;
    if(sum1 == 1 && sum2 == 9) return 11;
    for(int i = 0 ; i < 4; i++){
        int a = (sum1 & (1<<i)) != 0;
        int b = (sum2 & (1<<i)) != 0;
        if(a < b) {
            pos = i;
            break;
        }
    }
    return 10 + pos + 1;
}
int decode (int n, int q, int h) {
    if(h <= 10){
        int a = (q & (1<<(h-1))) != 0;
        return a;
    }
    int sum = 0;
    for(int i = 0 ; i < 10; i++) {
        int a = (q & (1<<i)) != 0;
        sum += a;
    }
    if(sum == 9) return 0;
    if(sum == 1) return 1;
    h -= 10;
    int a = (sum & (1<<(h-1))) != 0;
    return !a;
}

Compilation message

encoder.cpp: In function 'int encode(int, int, int)':
encoder.cpp:2:9: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
     int ok = 0;
         ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1822 ms 25672 KB Output is partially correct - maxh = 14
2 Partially correct 1831 ms 25672 KB Output is partially correct - maxh = 14