Submission #223068

# Submission time Handle Problem Language Result Execution time Memory
223068 2020-04-14T15:51:55 Z dolphingarlic cmp (balkan11_cmp) C++14
100 / 100
1777 ms 96312 KB
#include "cmp.h"

int delta[6]{1, 4097, 5121, 5377, 5441, 5457};

void remember(int n) {
    for (int i = 0; i < 6; i++) bit_set((n >> i * 2) + delta[i]);
}

int compare(int b) {
    int l = 0, r = 6;
    while (l != r) {
        int mid = (l + r) / 2;
        if (bit_get((b >> mid * 2) + delta[mid])) r = mid;
        else l = mid + 1;
    }

    if (!l) return 0;

    int last_digit = (b >> l * 2 - 2) & 3;
    if (last_digit > 1) {
        if (bit_get((((b >> l * 2) << 2) + 3) + delta[l - 1])) return -1;
        return 1;
    } else {
        if (bit_get(((b >> l * 2) << 2) + delta[l - 1])) return 1;
        return -1;
    }
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:19:34: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
     int last_digit = (b >> l * 2 - 2) & 3;
                            ~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1777 ms 96312 KB Output is correct - maxAccess = 10, score = 100