답안 #52538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52538 2018-06-26T06:56:01 Z someone_aa 비교 (balkan11_cmp) C++17
0 / 100
1175 ms 105044 KB
#include "cmp.h"
#include <vector>
using namespace std;
void remember(int n) {
    int node = 1;
    for(int i=11;i>=0;i--) {
        bit_set(node);
        if(n&(1<<i)) node = 2 * node + 1;
        else node = 2 * node;
    }
    bit_set(node);
}

int compare(int b) {
    //edit this
    int node = 1;
    vector<int>nodes;
    for(int i=11;i>=0;i--) {
        nodes.push_back(node);
        if(b&(1<<i)) node = 2 * node + 1;
        else node = 2 * node;
    }
    nodes.push_back(node);

    int li = 0, ri = nodes.size()-1;
    while(li < ri) {
        int mid = (li+ri)/2;
        if(bit_get(nodes[mid])) ri = mid;
        else li = mid + 1;
    }

    if(li == nodes.size() -1) return 0;
    else {
        if(nodes[li] * 2 == nodes[li+1]) return -1;
        else return 1;
    }
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:32:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(li == nodes.size() -1) return 0;
        ~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1175 ms 105044 KB ZERO POINTS: For a=3040 and b=3318, correct answer is 1, got 0