제출 #1287508

#제출 시각아이디문제언어결과실행 시간메모리
1287508Namkhing메시지 (IOI24_message)C++20
30.33 / 100
525 ms828 KiB
#include "message.h"
#include <bits/stdc++.h>
using namespace std;

void send_message(std::vector<bool> M, std::vector<bool> C) {
    vector<int> pos;
    for (int i = 0; i < 30; i++) {
        send_packet(vector<bool>(31, C[i]));
        if (!C[i]) {
            pos.push_back(i);
        }
    }
    if (pos.size() == 15) {
        pos.push_back(30);
    }
    int n = M.size() - 1;
    vector<bool> v(31);
    for (int i = 0; i < 10; i++) {
        if (n & (1 << i)) {
            v[pos[i]] = true;
        }
    }
    send_packet(v);
    for (int i = 0; i <= n; i += 16) {
        vector<bool> v(31);
        for (int j = i; j <= min(i + 15, n); j++) {
            v[pos[j-i]] = M[j];
        }
        send_packet(v);
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
    vector<bool> ans;
    vector<int> pos;
    for (int i = 0; i < 30; i++) {
        int cnt = 0;
        for (bool x : R[i]) {
            cnt += x;
        }
        if (cnt < 16) {
            pos.push_back(i);
        }
    }
    if (pos.size() == 15) {
        pos.push_back(30);
    }
    int n = 0;
    for (int i = 9; i >= 0; i--) {
        n = n * 2 + R[30][pos[i]];
    }
    for (int i = 31; i < R.size(); i++) {
        for (int j = 0; j <= min(15, n); j++) {
            ans.push_back(R[i][pos[j]]);
        }
        n -= 16;
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...