Submission #338907

#TimeUsernameProblemLanguageResultExecution timeMemory
338907Bertedcmp (balkan11_cmp)C++14
100 / 100
2513 ms102324 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...