Submission #950797

# Submission time Handle Problem Language Result Execution time Memory
950797 2024-03-20T17:39:41 Z Nhoksocqt1 Bit Shift Registers (IOI21_registers) C++17
33 / 100
1 ms 436 KB
#ifndef Nhoksocqt1
    #include "registers.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXM = 100;
const int MAXB = 2000;

int nArr, k, maxInstr;

#ifdef Nhoksocqt1
bool regs[MAXM][MAXB];

void append_move(int t, int x);
void append_store(int t, vector<bool> v);
void append_and(int t, int x, int y);
void append_or(int t, int x, int y);
void append_xor(int t, int x, int y);
void append_not(int t, int x);
void append_left(int t, int x, int p);
void append_right(int t, int x, int p);
void append_add(int t, int x, int y);
void append_print(int t);

#endif // Nhoksocqt1

void findMinElement(void) {
    vector<bool> v(MAXB, 1);
    append_store(1, v);
    for (int i = k; i < MAXB; ++i)
        v[i] = 0;

    append_store(2, v);

    append_and(10, 0, 2);
    for (int i = 1; i < nArr; ++i) {
        append_xor(9, 10, 1);
        append_right(3, 0, i * k);
        append_and(3, 3, 2);
        append_add(4, 3, 9);
        append_right(4, 4, MAXB - k);
        append_and(3, 3, 4);
        append_xor(4, 4, 2);
        append_and(10, 10, 4);

        append_or(10, 10, 3);
    }

    append_move(0, 10);
    //append_print(10);
}

void construct_instructions(int queryType, int _N, int _K, int _Q) {
    nArr = _N, k = _K, maxInstr = _Q;
    if(queryType == 0)
        findMinElement();
}

#ifdef Nhoksocqt1

void append_move(int t, int x) {
    assert(0 <= min({t, x}) && max({t, x}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = regs[x][i];
}

void append_store(int t, vector<bool> v) {
    assert(sz(v) == MAXB);
    assert(0 <= t && t < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = v[i];
}

void append_and(int t, int x, int y) {
    assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = regs[x][i] & regs[y][i];
}

void append_or(int t, int x, int y) {
    assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = regs[x][i] | regs[y][i];
}

void append_xor(int t, int x, int y) {
    assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = regs[x][i] ^ regs[y][i];
}

void append_not(int t, int x) {
    assert(0 <= min({t, x}) && max({t, x}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = 1 - regs[x][i];
}

void append_left(int t, int x, int p) {
    assert(0 <= p && p <= MAXB);
    assert(0 <= min({t, x}) && max({t, x}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = (i < p) ? 0 : regs[x][i - p];
}

void append_right(int t, int x, int p) {
    assert(0 <= p && p <= MAXB);
    assert(0 <= min({t, x}) && max({t, x}) < MAXB);
    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = (i + p >= MAXB) ? 0 : regs[x][i + p];
}

void append_add(int t, int x, int y) {
    assert(0 <= min({t, x, y}) && max({t, x, y}) < MAXB);

    __int128 a(0), b(0), pw2(1);
    for (int i = 0; i < MAXB; ++i) {
        a += pw2 * regs[x][i];
        b += pw2 * regs[y][i];
        pw2 *= 2;
    }

    a += b;
    for (int i = 0; i < MAXB; ++i) {
        regs[t][i] = a % 2;
        a /= 2;
    }
}

void append_print(int t) {
    cout << "ANSWER: ";
    for (int i = 0; i < nArr; ++i) {
        int res(0);
        for (int j = 0; j < k; ++j)
            res |= (1 << j) * regs[t][i * k + j];

        cout << res << ' ';
    }

    cout << '\n';
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "registers"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    int s, n, k, q;
    cin >> s >> n >> k >> q;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j < k; ++j)
            regs[0][i * k + j] = (a >> j & 1);
    }

    construct_instructions(s, n, k, q);

    return 0;
}

#endif // Nhoksocqt1
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Incorrect sorting
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Incorrect sorting
2 Halted 0 ms 0 KB -