Submission #566818

# Submission time Handle Problem Language Result Execution time Memory
566818 2022-05-22T22:02:46 Z Deepesson cmp (balkan11_cmp) C++17
100 / 100
3927 ms 102196 KB
#include <bits/stdc++.h>
#include "cmp.h"

void bit_set(int addr);
int bit_get(int addr);
bool marcas[15]={};

void remember(int n) {
    std::vector<int> vec;
    while(n){
        vec.push_back(n%4);
        n/=4;
    }
    while(vec.size()<6) vec.push_back(0);
    std::reverse(vec.begin(),vec.end());

    int base=1;
    for(int i=0;i!=vec.size();++i){
        base*=4;
        base+=vec[i];
        bit_set(base);
    }

}

int compare(int b) {
    std::vector<int> vec;
    while(b){
        vec.push_back(b%4);
        b/=4;
    }
    while(vec.size()<6) vec.push_back(0);
    std::reverse(vec.begin(),vec.end());

    int l=0,r=6;
    while(l<r){
        int m = (l+r+1)/2;
        int base=1;
        for(int i=0;i<m;++i){
            base*=4;
            base+=vec[i];
        }
        int x = bit_get(base);
        if(x){
            l=m;
        }else r=m-1;
    }
    ///Sao iguais
    if(l==6){
        return 0;
    }
    ///Eh maior
    if(vec[l]==3){
        return 1;
    }
    ///Eh menor
    if(!vec[l]){
        return -1;
    }
    int base=1;
    for(int i=0;i<l;++i){
        base*=4;
        base+=vec[i];
    }
    ///Checar o zero
    if(vec[l]==1)
    {
        base*=4;
        if(bit_get(base)){
            return 1;
        }else return -1;
    }else {
        base*=4;base+=3;
        if(bit_get(base)){
            return -1;
        }else return 1;
    }
}

Compilation message

cmp.cpp: In function 'void remember(int)':
cmp.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i!=vec.size();++i){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3927 ms 102196 KB Output is correct - maxAccess = 10, score = 100