Submission #728010

# Submission time Handle Problem Language Result Execution time Memory
728010 2023-04-21T19:21:30 Z rainboy cmp (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;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1883 ms 102184 KB Output is correct - maxAccess = 10, score = 100