Submission #1291804

#TimeUsernameProblemLanguageResultExecution timeMemory
1291804lucas110550메시지 (IOI24_message)C++20
0 / 100
39 ms780 KiB
#include <vector>
#include "message.h"

void send_message(std::vector<bool> M, std::vector<bool> C) {
    int S = (int)M.size();
    int P = (S + 15) / 16;

    // fixed_indices: positions i in [0,30] where C[i] == 0 (already sorted by construction)
    std::vector<int> fixed_indices;
    fixed_indices.reserve(31);
    for (int i = 0; i < 31; ++i) if (!C[i]) fixed_indices.push_back(i);

    for (int k = 0; k < P; ++k) {
        std::vector<bool> packet(31, false);
        int start = 16 * k;
        for (int j = 0; j < 16; ++j) {
            int pos = start + j;
            packet[fixed_indices[j]] = (pos < S) ? M[pos] : false;
        }
        (void)send_packet(packet);
    }

    // packet0
    {
        std::vector<bool> packet0(31, false);
        for (int j = 0; j < 11; ++j) {
            packet0[fixed_indices[j]] = ((S >> j) & 1) != 0;
        }
        for (int j = 11; j < 16; ++j) packet0[fixed_indices[j]] = true;
        (void)send_packet(packet0);
    }

    // packet1
    {
        std::vector<bool> packet1(31, false);
        for (int j = 0; j < 11; ++j) {
            packet1[fixed_indices[j]] = !(((S >> j) & 1) != 0);
        }
        for (int j = 11; j < 16; ++j) packet1[fixed_indices[j]] = false;
        (void)send_packet(packet1);
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
    std::vector<bool> M;
    if (R.size() < 2) return M;

    const auto& extra0 = R[R.size() - 2];
    const auto& extra1 = R[R.size() - 1];

    std::vector<int> fixed_indices;
    fixed_indices.reserve(31);
    for (int i = 0; i < 31; ++i) {
        if (extra0[i] != extra1[i]) fixed_indices.push_back(i);
    }

    int S = 0;
    for (int j = 0; j < 11 && j < (int)fixed_indices.size(); ++j) {
        if (extra0[fixed_indices[j]]) S |= (1 << j);
    }

    int P = (S + 15) / 16;
    for (int k = 0; k < P && k < (int)R.size(); ++k) {
        const auto& packet = R[k];
        int start = 16 * k;
        if (start >= S) break;
        for (int j = 0; j < 16; ++j) {
            int pos = start + j;
            if (pos >= S) break;
            M.push_back(packet[fixed_indices[j]]);
        }
    }
    return M;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...