Submission #45450

# Submission time Handle Problem Language Result Execution time Memory
45450 2018-04-14T06:51:24 Z smu201111192 cmp (balkan11_cmp) C++17
100 / 100
2125 ms 102136 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]
   int ask1 = rem / 4 * 4 + 0;
       ^~~~
cmp.cpp:34:7: warning: unused variable 'ask2' [-Wunused-variable]
   int ask2 = rem / 4 * 4 + 3; 
       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2125 ms 102136 KB Output is correct - maxAccess = 10, score = 100