Submission #147946

# Submission time Handle Problem Language Result Execution time Memory
147946 2019-08-31T09:23:58 Z evpipis cmp (balkan11_cmp) C++11
91 / 100
1593 ms 82552 KB
#include "cmp.h"

const int lg = 12, k = 3;

int match(int pos, int num){
    return pos*(1<<k) + num + 1;
}

void remember(int a) {
    for (int pos = lg/k-1; pos >= 0; pos--){
        int num = (a>>(k*pos))%(1<<k);
        bit_set(match(pos, num));
        //printf("pos = %d, num = %d, match = %d\n", pos, num, match(pos, num));
    }
}

int compare(int b) {
    for (int pos = lg/k-1; pos >= 0; pos--){
        int num = (b>>(k*pos))%(1<<k);

        if (bit_get(match(pos, num)))
            continue;

        if (num < (1<<k)/2){
            for (int j = 0; j < num; j++)
                if (bit_get(match(pos, j)))
                    return 1;
            return -1;
        }
        else{
            for (int j = (1<<k)-1; j > num; j--)
                if (bit_get(match(pos, j)))
                    return -1;
            return 1;
        }
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Partially correct 1593 ms 82552 KB Output is partially correct - maxAccess = 11, score = 91