Submission #1197277

#TimeUsernameProblemLanguageResultExecution timeMemory
1197277totoroBit Shift Registers (IOI21_registers)C++20
21 / 100
0 ms328 KiB
#include "registers.h"

#define append_print(x) 42

#include <iostream>
#include <set>

const int b = 2000;

struct Allocator {
    std::set<int> available;
    void init() {
        for (int i = 0; i < b; ++i) available.insert(i);
    }
    void free(int i) {
        available.insert(i);
    }
    int create() {
        if (available.empty()) {
            std::cout << "ALLOCATOR: FAILED TO ALLOCATE: NOT ENOUGH FREE SPACE" << std::endl;
            exit(1);
        }
        int i = *available.begin();
        available.erase(available.begin());
        return i;
    }
};

void construct_instructions(int s, int n, int k, int q) {
    std::vector<bool> buf(b);

    auto clearbuf = [&buf]() {
        buf.assign(b, 0);
    };

    Allocator alloc;
    alloc.init();

    /* READ INPUT */
    int in1 = alloc.create();
    int in2 = alloc.create();
    int msk = alloc.create();
    clearbuf();
    for (int i = 0; i < k; ++i) buf[i] = 1;
    append_store(msk, buf);
    append_and(in2, in1, msk);
    append_right(in1, in1, k);

    append_print(in1);
    append_print(in2);

    /* FIRST BIT */
    int firstbit = alloc.create();
    append_and(firstbit, in1, in2);
    int negfirstbit = alloc.create();
    append_not(negfirstbit, firstbit);

    append_print(firstbit);
    append_print(negfirstbit);

    /* DISABLE NUMBERS */
    int aux1 = alloc.create();
    int aux2 = alloc.create();
    append_and(aux1, in1, negfirstbit);
    append_and(aux2, in2, negfirstbit);
    append_right(aux1, aux1, 1);
    append_right(aux2, aux2, 1);
    append_or(in1, in1, aux1);
    append_or(in2, in2, aux2);

    append_print(in1);
    append_print(in2);
    append_print(aux1);
    append_print(aux2);

    /* SECOND BIT */
    int secondbit = alloc.create();
    append_and(secondbit, in1, in2);

    append_print(secondbit);

    /* COMBINE */
    clearbuf();
    buf[1] = 1;
    append_store(msk, buf);
    append_and(firstbit, firstbit, msk);
    append_or(in1, firstbit, secondbit);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...