Submission #26790

# Submission time Handle Problem Language Result Execution time Memory
26790 2017-07-05T17:30:48 Z baactree cmp (balkan11_cmp) C++14
0 / 100
982 ms 90952 KB
#include "cmp.h"
//4+3+3=10
void remember(int n) {
    int ri=10240;
    bit_set(ri-n);
    ri-=4096;
    bit_set(ri-n/64);
    ri-=64;
    int a,b;
    a=n/64;
    bit_set(ri-a/8);
    ri-=8;
    b=n%64;
    bit_set(ri-b/8);
}

int compare(int b) {
    //일치하는 경우 제외
    int ri=10240;
    if(bit_get(ri-b))
        return 0;
    ri-=4096;
    int k=b/64;
    //일치함 따라서 뒤 6비트 봐야함
    if(bit_get(ri-k)){
        ri-=64;
        ri-=8;
        int p=b%64;
        //일치함 뒤 3비트로 확인해야함 3번 구간
        if(bit_get(ri-p/8)){
            int r=0;
            int t=7<<r;
            int q=(b&t)>>r;
            int w=b&(~t);
            if(q<4){
                //0 1 2
                for(int i=0;i<q;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return 1;
                }
                return -1;
            }
            else{
                //5 6 7
                for(int i=q+1;i<8;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return -1;
                }
                return 1;
            }
        }
        //불일치함 앞 3비트로 확인해야함 2번 구간
        else{
            int r=3;
            int t=7<<r;
            int q=(b&t)>>r;
            int w=b&(~t);
            if(q<4){
                //0 1 2
                for(int i=0;i<q;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return 1;
                }
                return -1;
            }
            else{
                //5 6 7
                for(int i=q+1;i<8;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return -1;
                }
                return 1;
            }
        }
    }
    //불일치함 따라서 앞 6비트 봐야함
    else{
        ri-=64;
        int p=b/64;
        //일치함 뒤 3비트로 확인해야함 1번 구간
        if(bit_get(ri-p/8)){
            int r=6;
            int t=7<<r;
            int q=(b&t)>>r;
            int w=b&(~t);
            if(q<4){
                //0 1 2
                for(int i=0;i<q;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return 1;
                }
                return -1;
            }
            else{
                //5 6 7
                for(int i=q+1;i<8;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return -1;
                }
                return 1;
            }
        }
        //불일치함 앞 3비트로 확인해야함 0번 구간
        else{
            int r=9;
            int t=7<<r;
            int q=(b&t)>>r;
            int w=b&(~t);
            if(q<4){
                //0 1 2
                for(int i=0;i<q;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return 1;
                }
                return -1;
            }
            else{
                //5 6 7
                for(int i=q+1;i<8;i++){
                    int now=w+i<<r;
                    if(bit_get(10240-now))
                        return -1;
                }
                return 1;
            }
        }
    }
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:38:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:47:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:63:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:72:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:93:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:102:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:118:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
cmp.cpp:127:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
                     int now=w+i<<r;
                             ~^~
# Verdict Execution time Memory Grader output
1 Incorrect 982 ms 90952 KB ZERO POINTS: bit_get with address out of range