Submission #1261280

#TimeUsernameProblemLanguageResultExecution timeMemory
1261280biankBit Shift Registers (IOI21_registers)C++20
100 / 100
1 ms584 KiB
#include "registers.h"
#include <bits/stdc++.h>
 
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define dforsn(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define dforn(i, n) dforsn(i, 0, n)
 
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
 
#define pb push_back
#define eb emplace_back
 
#define fst first
#define snd second
 
using namespace std;
 
using vi = vector<int>;
using ii = pair<int, int>;
using vb = vector<bool>;

const int B = 2000;

void construct_instructions(int s, int n, int k, int /*q*/) {
    vb v(B);
    forn(i, B) v[i] = i % (2 * k) == 0;
    append_store(99, v);
    forn(i, B) v[i] = (i / k) % 2 == 0;
    append_store(98, v);
    forn(i, B) v[i] = i >= n * k;
    append_store(97, v);
    append_or(0, 0, 97);
    auto getOrder = [&](int shift) {
        if (shift > 0) append_right(1, 0, shift);
        else append_left(1, 0, -shift);
        append_not(2, 1);
        append_and(2, 2, 98);
        append_and(4, 0, 98);
        append_add(3, 4, 2);
        append_right(3, 3, k);
        append_and(3, 3, 99);
        append_add(3, 3, 98);
    };
    if (s == 0) {
        int steps = 0;
        while ((1 << steps) < n) steps++;
        int shift = k;
        forn(_, steps) {
            getOrder(shift);
            append_and(5, 3, 4);
            append_not(6, 3);
            append_and(6, 1, 6);
            append_or(0, 5, 6);
            shift *= 2;
        }
    } else {
        int shift = k;
        forn(step, n) {
            getOrder(shift);
            append_not(6, 3);
            append_and(7, 0, 3);
            append_and(8, 1, 6);
            append_or(9, 7, 8);
            append_and(9, 9, 98);
            append_and(7, 1, 3);
            append_and(8, 0, 6);
            append_or(10, 7, 8);
            append_and(10, 10, 98);
            if (shift > 0) append_left(10, 10, shift);
            else append_right(9, 9, -shift);
            append_or(0, 9, 10);
            shift *= -1;
        }
    }
}
#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...