Submission #797537

# Submission time Handle Problem Language Result Execution time Memory
797537 2023-07-29T15:20:53 Z caganyanmaz Bit Shift Registers (IOI21_registers) C++17
100 / 100
1 ms 596 KB
#include <bits/stdc++.h>
#define pb push_back
#include "registers.h"
using namespace std;

constexpr static int b = 2000;
vector<bool> v(b);
int n, s, k, q;

void fill_right(int i, int c, int tmp);

void expand_numbers()
{
        for (int i = 0; i < b; i++)
                v[i] = (i % (2*k)) < k;
        append_store(99, v);
        append_left(1, 0, (n-1 + (n&1)) * k);
        append_or(0, 0, 1);
        append_and(0, 0, 99);
}

void create_stores(int ones, int eleves)
{
        for (int i = 0; i < b; i++)
                v[i] = !(i%k);
        append_store(ones, v);
        for (int i = 0; i < b; i++)
                v[i] = (i%(2*k)) == (k);
        append_store(eleves, v);
}

void find_minimum()
{
        expand_numbers();
        const int ONES = 9;
        const int ELEVES = 10;
        create_stores(ONES, ELEVES);
        while (n > 1)
        {
                int step = n / 2;
                append_right(1, 0, step * k*2);
                append_not(2, 1);
                append_add(2, 2, ONES); // 2 is negative 1 right now
                append_add(2, 0, 2);
                append_and(2, 2, ELEVES);
                //append_print(2);
                fill_right(2, k, 3);
                append_not(3, 2);
                // 2 means 1 is bigger, 3 means 0 is bigger
                append_and(1, 1, 2);
                append_and(0, 0, 3);
                append_or(0, 0, 1);
                n -= step;
        }
}

const int LEFT = 99;
const int RIGHT = 98;
const int ONES = 97;
const int ELEVES = 96;
const int NELEVES = 95;
const int LEFT_FILLER = 94;
const int RELEVES = 93;

const int RIGHT_DIRECTION = 0;
const int LEFT_DIRECTION = 1;

void compare_push(int direction)
{
                append_or(0, 0, LEFT_FILLER);
        append_and(1, 0, LEFT);
        append_and(0, 0, RIGHT);
        if (direction == RIGHT_DIRECTION)
                append_right(1, 1, k);
        else
                append_left(1, 1, k);
        append_print(0);
        append_print(1);
        append_not(2, 1);
        append_print(2);
        //append_and(2, 2, RELEVES);
        //append_add(2, 2, ONES);
        //append_or(2, 2, ELEVES);
        append_print(2);
        append_add(2, 2, 0);
        append_and(2, 2, ELEVES);
        append_print(2);
        fill_right(2, k, 3);
        append_not(3, 2);
        // 2 if 1 is bigger, 3 if 0 is bigger
        // 4 minimum, 5 maximum
        append_and(6, 0, 2);
        append_and(7, 1, 3);
        append_or(4, 6, 7);
        append_and(6, 0, 3);
        append_and(7, 1, 2);
        append_or(5, 6, 7);
        append_print(4);
        append_print(5);
        if (direction == RIGHT_DIRECTION)
                append_left(5, 5, k);
        else
                append_right(4, 4, k);
        append_or(0, 4, 5);
        append_print(0);
        append_print(55);
}

void sort()
{
        create_stores(ONES, ELEVES);
        append_not(NELEVES, ELEVES);
        for (int i = 0; i < b; i++)
                v[i] = (i % (2*k)) < k;
        append_store(RIGHT, v);
        append_not(LEFT, RIGHT);
        for (int i = 0; i < b; i++)
                v[i] = i >= n*k && i < (n+1)*k;
        append_store(LEFT_FILLER, v);
        append_or(RELEVES, RIGHT, ELEVES);
        for (int i = 0; i <= n; i++)
        {
                compare_push(i&1);
        }
}

void construct_instructions(int ss, int nn, int kk, int qq)
{
        s = ss, n = nn, k = kk, q = qq;
        if (s == 0)
                find_minimum();
        else
                sort();
}



void fill_right(int i, int c, int tmp)
{
        c++;
        while (c > 1)
        {
                if (c&1)
                {
                        c--;
                        append_right(tmp, i, 1);
                }
                else
                {
                        c >>= 1;
                        append_right(tmp, i, c);
                }
                append_or(i, i, tmp);
        }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 432 KB Output is correct