Submission #400875

# Submission time Handle Problem Language Result Execution time Memory
400875 2021-05-08T18:59:14 Z phathnv cmp (balkan11_cmp) C++11
100 / 100
2005 ms 102188 KB
#include "cmp.h"
#include <cassert>
using namespace std;
void remember(int n) {
	n += 4096;
	while (n > 1){
		bit_set(n);
		n /= 4;
	}
}

int compare(int b) {
	b += 4096;
	int lo = 0;
	int hi = 6;
	int same = 1;

	int rem = 0;
	while (lo <= hi){
		int mid = (lo + hi) / 2;
		if (!bit_get(b >> (mid * 2)) && mid != 6) {
			lo = mid + 1;
			rem = b >> (mid * 2);
			same = 0;
		}
		else { hi = mid - 1;}
	}
	if (same) return 0;
	if (rem % 4 == 0){
		return -1;
	}
	else if (rem % 4 == 1){
		int ask1 = rem / 4 * 4 + 0;
		int ask2 = rem / 4 * 4 + 3;
		return bit_get(rem / 4 * 4 + 0) ? 1 : -1;
	}
	else if (rem % 4 == 2){
		return bit_get(rem / 4 * 4 + 3) ? -1 : 1;
	}
	else{
		return 1;
	}
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:33:7: warning: unused variable 'ask1' [-Wunused-variable]
   33 |   int ask1 = rem / 4 * 4 + 0;
      |       ^~~~
cmp.cpp:34:7: warning: unused variable 'ask2' [-Wunused-variable]
   34 |   int ask2 = rem / 4 * 4 + 3;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2005 ms 102188 KB Output is correct - maxAccess = 10, score = 100