답안 #43921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43921 2018-03-28T07:22:03 Z dhkim0225 비교 (balkan11_cmp) C++14
0 / 100
1075 ms 85496 KB
#include "cmp.h"

void remember(int n) {
	n = n + 1;

	int target = 2048;
	int cnt = 1;
	while (cnt <= 12) {
		if (target < n) {
			bit_set(target);
			target += (target >> cnt);
		}
		else if (target > n) {
			bit_set(target);
		}
		else {
			bit_set(target);
			break;
		}
		cnt++;
	}
}

int compare(int b) {
	int target = 2048;
	int cnt = 1;

	if (bit_get(target) == 1) {
		while (cnt <= 12) {
			if (bit_get(target + target >> cnt))
				target += (target >> cnt);
			else if (bit_get(target - target >> cnt))
				target -= (target >> cnt);
			else
				break;
			cnt++;
		}
	}
	if (target > b)
		return -1;
	else if (target < b)
		return 1;
	else
		return 0;
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:30:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    if (bit_get(target + target >> cnt))
                ~~~~~~~^~~~~~~~
cmp.cpp:32:28: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
    else if (bit_get(target - target >> cnt))
                     ~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1075 ms 85496 KB ZERO POINTS: bit_get with address out of range