답안 #728010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728010 2023-04-21T19:21:30 Z rainboy 비교 (balkan11_cmp) C
100 / 100
1883 ms 102184 KB
#include "cmp.h"

#define A	4096

void remember(int a) {
	for (a += A; a > 1; a >>= 2)
		bit_set(a);
}

int compare(int b) {
	int lower = -1, upper = 6, h;

	while (upper - lower > 1) {
		h = (lower + upper) / 2;
		if (bit_get(A + b >> h * 2))
			upper = h;
		else
			lower = h;
	}
	if (lower == -1)
		return 0;
	switch ((A + b >> lower * 2 & 3)) {
		case 0:
			return -1;
		case 1:
			return bit_get((A + b >> lower * 2) - 1) ? 1 : -1;
		case 2:
			return bit_get((A + b >> lower * 2) + 1) ? -1 : 1;
		case 3:
			return 1;
		default:
			return 0;
	}
}

Compilation message

cmp.c: In function 'compare':
cmp.c:15:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |   if (bit_get(A + b >> h * 2))
      |                 ^
cmp.c:22:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |  switch ((A + b >> lower * 2 & 3)) {
      |             ^
cmp.c:26:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |    return bit_get((A + b >> lower * 2) - 1) ? 1 : -1;
      |                      ^
cmp.c:28:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |    return bit_get((A + b >> lower * 2) + 1) ? -1 : 1;
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1883 ms 102184 KB Output is correct - maxAccess = 10, score = 100