Submission #796730

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

constexpr static int b = 2000;
int n, s, k, q;

void get_second(int t)
{
        append_left(t, t, b-2);
        append_right(t, t, b-1);
}

void _fix(int t)
{
        append_xor(3, t, 2);
        get_second(3);
        append_or(t, t, 3);
}

void subtask2()
{
        if (k == 2)
        {
                append_right(1, 0, 2);
                append_and(2, 0, 1);
                _fix(0);
                _fix(1);
                append_and(0, 0, 1);
        }
        else
        {
                append_right(1, 0, 1);
                append_and(0, 0, 1);
        }
}

vector<bool> big;
vector<bool> small;

void preprocess()
{
        big.pb(true);
        small.pb(true);
        for (int i = 1; i < b; i++)
        {
                big.pb(true);
                small.pb(false);
        }
}


// 3 ops
// to y: first 1000 bits on if i is not zero, all bits off if i 0
// to t: opposite
// NOTE: Assumed i doesn't have open bits after 1000
void set_zero(int i, int t, int y)
{
        append_store(t, big);
        append_add(t, i, t);
        append_right(t, t, b/2);
        append_not(y, t);
}


vector<bool> create_mask(int i)
{
        vector<bool> mask(b, false);
        for (int l = 0; l < n; l++)
        {
                mask[l*k+i] = true;
        }
        return mask;
}
constexpr static int MXLOG = 10;

void fill_right(int i, int c, int tmp)
{
        c++;
        while (c>1)
        {
                if (c&1)
                {
                        c--;
                        append_right(tmp, i, 1);
                        append_or(i, i, tmp);
                }
                else
                {
                        c>>=1;
                        append_right(tmp, i, c);
                        append_or(i, i, tmp);
                }
        }
}

void fill_left(int i, int c, int tmp)
{
        c++;
        while (c >1)
        {
                if (c&1)
                {
                        c--;
                        append_left(tmp, i, 1);
                        append_or(i, i, tmp);
                }
                else
                {
                        c>>=1;
                        append_left(tmp, i, c);
                        append_or(i, i, tmp);
                }
        }
}

void subtask4()
{
        append_move(5, 0);
        vector<bool> sss;
        for (int i = 0; i < k*n; i++)
                sss.pb(true);
        for (int i = k*n; i < b; i++)
                sss.pb(false);
        append_store(10, sss);
        int l = k;
        while (l>1)
        {

                if (l&1)
                {
                        append_right(6, 5, 1);
                        append_or(5, 5, 6);
                        l--;
                }
                else
                {
                        l >>= 1;
                        append_right(6, 5, l);
                        append_or(5, 5, 6);
                }
        }
        append_not(5, 5);
        vector<bool> v = create_mask(0);
        append_store(6, v);
        append_and(6, 5, 6);
        set_zero(6, 7, 8);
        for (int i = k-1; i >= 0; i--)
        {
                vector<bool> v = create_mask(i);
                append_store(1, v);
                append_and(1, 0, 1);
                fill_right(1, i, 2);
                fill_left(1, k-1-i, 2);
                append_xor(1, 1, 10);
                append_and(3, 0, 1);
                append_store(2, big);
                append_add(2, 3, 2);
                append_right(2, 2, b/2);
                append_and(0, 0, 2);
                append_or(0, 0, 3);
        }
        for (int i = 0; i < 7; i++)
        {
                append_right(1, 0, k * (1<<i));
                append_or(0, 0, 1);
        }
        append_and(0, 0, 7);
}

void construct_instructions(int ss, int nn, int kk, int qq)
{
        preprocess();
        s = ss, n = nn, k = kk, q = qq;
        if (s == 0 && n == 2 && k <= 2)
                subtask2();
        else if (s == 0)
                subtask4();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Incorrect sorting
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Incorrect sorting
2 Halted 0 ms 0 KB -