Submission #1231353

#TimeUsernameProblemLanguageResultExecution timeMemory
1231353VMaksimoski008Message (IOI24_message)C++20
29.32 / 100
518 ms856 KiB
#include "message.h"
#include <bits/stdc++.h>
using namespace std;

void send_message(vector<bool> M, vector<bool> C) {
    for(int i=0; i<31; i++) {
        send_packet(vector<bool>(31, C[i]));
    }

    int n = M.size();
    int c = 0;
    vector<bool> msg(31);
    for(int i=0; i<31; i++) {
        if(!C[i]) {
            msg[i] = n & (1 << c);
            c++;
        }
    }
    send_packet(msg);

    for(int i=0; i<n; i+=16) {
        msg = vector<bool>(31);
        int curr = i;
        for(int j=0; j<31&&curr<n; j++) {
            if(!C[j]) {
                msg[j] = M[curr++];
            }
        }
        send_packet(msg);
    }

}

vector<bool> receive_message(vector<vector<bool>> R) {
    vector<bool> ans;
    vector<int> is_ok(31);
    for(int i=0; i<31; i++) {
        int v = 0;
        for(bool b : R[i]) v += (b ? 1 : -1);
        is_ok[i] = (v <= 0);
    }

    int n = 0, c = 0;
    for(int i=0; i<31; i++) {
        if(is_ok[i]) {
            if(R[31][i]) n += (1 << c);
            c++;
        }
    }
    
    for(int i=32; i<R.size(); i++) {
        for(int j=0; j<31&&n; j++) {
            if(is_ok[j]) {
                ans.push_back(R[i][j]);
                n--;
            }
        }
    }

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...