답안 #951057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951057 2024-03-21T05:22:01 Z Nhoksocqt1 레지스터 (IOI21_registers) C++17
46 / 100
1 ms 432 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 sortArray(void) {
    vector<bool> v(MAXB, 1);
    append_store(99, v);
    for (int i = k; i < MAXB; ++i)
        v[i] = 0;

    append_store(98, v);

    for (int i = 1; i <= nArr; ++i) {
        append_right(i, 0, (i - 1) * k);
        append_and(i, i, 98);
    }

    for (int i = 1; i <= nArr; ++i) {
        for (int j = i + 1; j <= nArr; ++j) {
            append_xor(nArr + 1, i, 99);
            append_add(nArr + 2, nArr + 1, j);
            append_right(nArr + 2, nArr + 2, MAXB - k);
            append_and(nArr + 4, i, nArr + 2);
            append_and(nArr + 3, j, nArr + 2);
            append_xor(nArr + 2, nArr + 2, 98);
            append_and(nArr + 5, i, nArr + 2);
            append_and(nArr + 6, j, nArr + 2);
            append_or(i, nArr + 3, nArr + 5);
            append_or(j, nArr + 4, nArr + 6);
        }
    }

    append_move(0, 97);
    for (int i = 1; i <= nArr; ++i) {
        if(i > 1)
            append_left(i, i, (i - 1) * k);

        append_or(0, 0, i);
    }
}

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

    if(queryType == 1)
        sortArray();
}

#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);

    vector<int> v(MAXB, 0);
    for (int i = 0; i < MAXB; ++i)
        v[i] = (i < p) ? 0 : regs[x][i - p];

    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = v[i];
}

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

    vector<int> v(MAXB, 0);
    for (int i = 0; i < MAXB; ++i)
        v[i] = (i + p >= MAXB) ? 0 : regs[x][i + p];

    for (int i = 0; i < MAXB; ++i)
        regs[t][i] = v[i];
}

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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Wrong answer detected in grader
4 Halted 0 ms 0 KB -