답안 #795226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795226 2023-07-27T07:38:40 Z finn__ 레지스터 (IOI21_registers) C++17
47 / 100
1 ms 212 KB
#include "registers.h"
#include <vector>
#include <iostream>

constexpr size_t B = 2000;
constexpr int ONE = 50, ALL_ONES = 51, MASK = 52;

void construct_instructions(int s, int n, int k, int q)
{
    std::vector<bool> r(B);
    r[0] = 1;
    append_store(ONE, r);
    fill(r.begin() + 1, r.end(), 1);
    append_store(ALL_ONES, r);
    fill(r.begin(), r.end(), 0);
    for (int i = k; i < B; i += k)
        r[i] = 1;
    append_store(MASK, r);

    // writes min in a, max in b
    auto append_swap = [&](int a, int b)
    {
        append_not(40, a);
        append_add(40, 40, ONE);
        append_add(40, 40, b); // 40 : b - a

        append_xor(41, 40, a);
        append_xor(41, 41, b); // 41 : (b - a) ^ a ^ b
        append_and(40, 41, MASK);
        append_right(41, 40, k);
        append_not(41, 41);
        append_add(41, 41, ONE);
        append_add(42, 40, 41); // 42 : 1-mask if a > b, else 0-mask

        append_xor(43, a, b);
        append_and(43, 43, 42); // 43 : a_i ^ b_i if a_i > b_i
        append_xor(a, a, 43);   // a_i = min(a_i, b_i)
        append_xor(b, b, 43);   // b_i = max(a_i, b_I)
    };

    if (!s)
    {
        int l = 64;
        append_left(2, ALL_ONES, n * k);
        append_or(0, 0, 2);
        append_move(1, 0);
        append_right(0, 0, l * k); // 0 : upper half
        append_left(2, ALL_ONES, l * k);
        append_or(1, 1, 2); // 1 : lower half
        append_print(0);
        append_print(1);

        while (l)
        {
            append_swap(0, 1);
            l >>= 1;
            append_move(1, 0);
            append_right(0, 0, l * k);
            append_left(2, ALL_ONES, l * k);
            append_or(1, 1, 2);
            append_print(0);
            append_print(1);
        }
    }
    else
    {
    }
}

Compilation message

registers.cpp: In function 'void construct_instructions(int, int, int, int)':
registers.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   16 |     for (int i = k; i < B; i += k)
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Wrong answer detected in grader
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Incorrect sorting
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Incorrect sorting
2 Halted 0 ms 0 KB -