Submission #1221523

#TimeUsernameProblemLanguageResultExecution timeMemory
1221523nibertMessage (IOI24_message)C++20
0 / 100
112 ms816 KiB
#include <vector>
using namespace std;

// OJ will provide the implementation of this
extern vector<bool> send_packet(vector<bool> A);

// Constants
const int BITS = 31;       // Packet length
const int REPEAT = 3;      // Redundancy (must be ≥ 3 to tolerate 15 bad packets)
const int BITS_PER_PACKET = 10;  // You can safely fit 10 message bits with 3 repetitions each (3 * 10 = 30 bits)

// Global to coordinate encoding/decoding
vector<pair<int, int>> encode_map;  // (packet_index, bit_position)

void send_message(vector<bool> M, vector<bool> C) {
    encode_map.clear();

    int L = M.size();
    int packets_needed = (L + BITS_PER_PACKET - 1) / BITS_PER_PACKET * REPEAT;

    vector<vector<bool>> packets;

    int bit_index = 0;
    for (int block = 0; block < (L + BITS_PER_PACKET - 1) / BITS_PER_PACKET; ++block) {
        for (int r = 0; r < REPEAT; ++r) {
            vector<bool> pkt(BITS, 0);
            for (int b = 0; b < BITS_PER_PACKET && bit_index < L; ++b) {
                int pos = b * REPEAT + r;  // ensure different positions per repetition
                pkt[pos] = M[bit_index];
                if (r == 0) encode_map.push_back({packets.size(), pos});
            }
            packets.push_back(pkt);
        }
        bit_index += BITS_PER_PACKET;
    }

    for (auto& pkt : packets) {
        send_packet(pkt);
    }
}

vector<bool> receive_message(vector<vector<bool>> R) {
    vector<bool> decoded;
    for (int i = 0; i < encode_map.size(); ++i) {
        int base = (i / BITS_PER_PACKET) * REPEAT;
        int bit_pos = (i % BITS_PER_PACKET) * REPEAT;

        int ones = 0;
        for (int r = 0; r < REPEAT; ++r) {
            if (R[base + r][bit_pos + r]) ones++;
        }
        decoded.push_back(ones >= 2);
    }
    return decoded;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...