Submission #480785

# Submission time Handle Problem Language Result Execution time Memory
480785 2021-10-18T04:13:31 Z tranxuanbach cmp (balkan11_cmp) C++17
0 / 100
0 ms 200 KB
#include "cmp.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;

const int N = 12;

void remember(int a){
    int ta = 0, offset = 0;
    for (int i = 10; i >= 0; i -= 2){
        ta = ta * 4 + ((a & (1 << (i + 1))) ? 2 : 0) + ((a & (1 << i)) ? 1 : 0);
        bit_set(offset + ta);
        offset += (1 << (12 - i));
    }
}

int compare(int b){
    int hi = 5, lo = -1;
    while (hi > lo){
        int mid = (hi + lo + 1) / 2;
        int tb = 0, offset = 0;
        for (int i = 11; i >= 2 * mid; i--){
            tb = tb * 2 + ((b & (1 << i)) ? 1 : 0);
            if (i % 2 == 0 and i != 2 * mid){
                offset += (1 << (12 - i));
            }
        }
        if (bit_get(offset + tb)){
            hi = mid - 1;
        }
        else{
            lo = mid;
        }
    }
    if (lo == -1){
        return 0;
    }
    int tb = 0, offset = 0;
    for (int i = 11; i >= 2 * lo; i--){
        tb = tb * 2 + ((b & (1 << i)) ? 1 : 0);
        if (i % 2 == 0 and i != 2 * lo){
            offset += (1 << (12 - i));
        }
    }
    if (!(tb & 2) and !(tb & 1)){
        return -1;
    }
    if ((tb & 2) and (tb & 1)){
        return 1;
    }
    if (!(tb & 2) and (tb & 1)){
        if (bit_get(offset + tb - 1)){
            return 1;
        }
        else{
            return -1;
        }
    }
    if ((tb & 2) and !(tb & 1)){
        if (bit_get(offset + tb + 1)){
            return -1;
        }
        else{
            return 1;
        }
    }
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
   87 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 200 KB ZERO POINTS: bit_set with addr out of range 0