제출 #1337167

#제출 시각아이디문제언어결과실행 시간메모리
1337167SulA메시지 (IOI24_message)C++20
0 / 100
140 ms768 KiB
#include "message.h"
#include <iostream>
#define all(a) a.begin(), a.end()
#define popcount(x) __builtin_popcountll(x)
using namespace std;

void send_message(vector<bool> message, vector<bool> C) {
    int i;
    vector<int> pos;
    for (i = 0; i < 20; i++) {
        send_packet(vector<bool>(31, C[i]));
        if (C[i] == 0) pos.push_back(i);
    }
    for (int start = 20; start <= 25; start += 5) {
        vector<bool> send(31);
        for (i = 0; i < 5; i++)
            send[pos[i]] = C[start + i];
        send_packet(send);
    }
    for (i = 0; i < message.size(); i += 16) {
        vector<bool> packet(31);
        int j = i;
        for (int p : pos) if (j < message.size()) {
                packet[p] = message[j++];
            }
        send_packet(packet);
    }
    vector<bool> packet(31);
    for (i = 0; i < 4; i++) {
        packet[pos[i]] = (message.size() % 16) >> i & 1;
    }
    send_packet(packet);
}

vector<bool> receive_message(vector<vector<bool>> packets) {
    vector<int> C(31), pos;
    int i;
    for (i = 0; i < 20; i++) {
        int cnt[2] = {};
        for (auto b : packets[i]) {
            cnt[b]++;
        }
        C[i] = cnt[0] > cnt[1] ? 0 : 1;
        if (C[i] == 0) {
            pos.push_back(i);
        }
    }
    for (int start = 20; start <= 25; start++) {
        auto packet = packets[start/5 + 16];
        for (i = 0; i < 5; i++) {
            C[start + i] = packet[pos[i]];
        }
    }

    vector<bool> message;
    for (i = 22; i < packets.size() - 2; i++) {
        for (int j : pos) {
            message.push_back(packets[i][j]);
        }
    }
    int to_read = 0;
    for (i = 0; i < 4; i++) {
        to_read |= packets.back()[pos[i]] << i;
    }
    if (to_read == 0) to_read = 16;
    for (i = 0; i < to_read; i++) {
        message.push_back(packets[packets.size() - 2][pos[i]]);
    }
    return message;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...