Submission #338907

# Submission time Handle Problem Language Result Execution time Memory
338907 2020-12-24T08:27:12 Z Berted cmp (balkan11_cmp) C++14
100 / 100
2513 ms 102324 KB
#include "cmp.h"
#include <iostream>

using namespace std;

int B[6] = {};

void remember(int n) 
{
  	//cerr << "Initializing: " << n << "\n";
	for (int i = 5; i >= 0; i--) {B[i] = n & 3; n >>= 2;}
	B[0] ^= 4;
	for (int i = 1; i < 6; i++) {B[i] ^= (B[i - 1] << 2);}
	for (int i = 0; i < 6; i++) 
	{
		//cerr << "Toggling: " << B[i] << "\n";
		bit_set(B[i]);
	}
}

int compare(int b) 
{
	for (int i = 5; i >= 0; i--) {B[i] = b & 3; b >>= 2;}
	B[0] ^= 4;
	for (int i = 1; i < 6; i++) {B[i] ^= (B[i - 1] << 2);}
	int L = 0, R = 6;
	while (L < R)
	{
		int M = L + R >> 1;
		if (bit_get(B[M])) {L = M + 1;}
		else {R = M;}
	}
	//cerr << "L = " << L << "\n";
	if (L == 6) return 0;
	int pref = (L) ? (B[L - 1] << 2) : 4;
	if ((B[L] & 3) == 0) {return -1;}
	else if ((B[L] & 3) == 1) {return (bit_get(pref)) ? 1 : -1;}
	else if ((B[L] & 3) == 2) {return (bit_get((pref ^ 3))) ? -1 : 1;}
	else {return 1;}
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |   int M = L + R >> 1;
      |           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2513 ms 102324 KB Output is correct - maxAccess = 10, score = 100