Submission #1287523

#TimeUsernameProblemLanguageResultExecution timeMemory
1287523NamkhingMessage (IOI24_message)C++20
37.74 / 100
437 ms824 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;
    int cnt = 0;
    while (true) {
        send_packet(vector<bool>(31, C[cnt]));
        if (!C[cnt]) {
            pos.push_back(cnt);
        }
        cnt++;
        if (pos.size() == 2) {
            break;
        }
    }
    int now = cnt;
    while (now < 31) {
        int len = pos.size();
        vector<bool> v(31);
        for (int i = now; i < min(now + len, 31); i++) {
            v[pos[i-now]] = C[i];
            if (!C[i]) {
                pos.push_back(i);
            }
        }
        send_packet(v);
        now += len;
    }
    int need = 1040 - M.size() - 1;
    vector<bool> s(need, false);
    s.push_back(true);
    for (bool x : M) {
        s.push_back(x);
    }
    for (int i = 0; i < 1040; i += 16) {
        vector<bool> v(31);
        for (int j = i; j < i + 16; j++) {
            v[pos[j-i]] = s[j];
        }
        send_packet(v);
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
    vector<bool> ans;
    vector<int> pos;
    int cnt = 0;
    while (true) {
        int sum = 0;
        for (bool x : R[cnt]) {
            sum += x;
        }
        if (sum < 16) {
            pos.push_back(cnt);
        }
        cnt++;
        if (pos.size() == 2) {
            break;
        }
    }
    int now = cnt;
    while (now < 31) {
        int len = pos.size();
        for (int i = now; i < min(now + len, 31); i++) {
            bool x = R[cnt][pos[i-now]];
            if (!x) {
                pos.push_back(i);
            }
        }
        now += len;
        cnt++;
    }
    bool flag = false;
    for (int i = cnt; i < R.size(); i++) {
        for (int j = 0; j < 16; j++) {
            if (flag) {
                ans.push_back(R[i][pos[j]]);
            }
            if (R[i][pos[j]]) {
                flag = true;
            }
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...