Submission #39472

# Submission time Handle Problem Language Result Execution time Memory
39472 2018-01-15T16:24:30 Z smu201111192 cmp (balkan11_cmp) C++14
100 / 100
2181 ms 99656 KB
#include "cmp.h"
void remember(int n){
    int a[4]; int pos = 3;
    if(n == 2888){
        int abc=3;
    }
    while(pos >= 0){
        a[pos--] = (n % 8); n/=8;
    }
    int cur = 1;
    for(int i=0;i<4;i++){
        cur = cur * 8 + a[i];
        bit_set(cur);
    }
}
int compare(int b) {
    int temp[4];
    if(b == 3141){
        int abc=3;
    }
    int n = b;
    int a[4]; int pos = 3;
    while(pos >= 0){
        a[pos--] = (n % 8); n/=8;
    }
    int cur = 1; int i = -1;
    int lo = 0;
    int hi = 3;
    for(int j=0;j<4;j++){
        temp[j] = cur * 8 + a[j];
        cur = cur * 8 + a[j];
    }
    while(lo <= hi){
        int mid = (lo+hi)/2;
        int bit = bit_get(temp[mid]);
        if(bit == 1){
            lo = mid + 1;
            if(mid > i) i = mid;
        }
        else{
            hi = mid - 1;
        }
    }
    i++;
    if(i == 4)return 0;
    cur = temp[i]; cur /= 8;
    int chk = -1;
    if(a[i] == 0)return -1;
    if(a[i] == 7)return 1;
    if(a[i] <= 3){
        for(int k = 0 ; k < a[i]; k ++){
            int bit = bit_get(cur * 8 + k);
            if(bit == 1){
                chk = k;
                break;
            }
        }
        if(chk == -1) return -1;
        else return 1;
    }
    else{
        for(int k = a[i] + 1; k <= 7; k++){
            int bit = bit_get(cur * 8 + k);
            if(bit == 1){
                chk=k;
                break;
            }
        
        }
        if(chk == -1) return 1;
        else return -1;
    }
    return 1;
}

Compilation message

cmp.cpp: In function 'void remember(int)':
cmp.cpp:5:13: warning: unused variable 'abc' [-Wunused-variable]
         int abc=3;
             ^~~
cmp.cpp: In function 'int compare(int)':
cmp.cpp:19:13: warning: unused variable 'abc' [-Wunused-variable]
         int abc=3;
             ^~~
# Verdict Execution time Memory Grader output
1 Correct 2181 ms 99656 KB Output is correct - maxAccess = 10, score = 100