Submission #1287545

#TimeUsernameProblemLanguageResultExecution timeMemory
1287545Namkhing메시지 (IOI24_message)C++20
77.38 / 100
416 ms828 KiB
#include "message.h"
#include <bits/stdc++.h>
using namespace std;

void send_message(std::vector<bool> M, std::vector<bool> C) {
    int pos = 0;
    for (int i = 0; i < 31; i++) {
        if (!C[i]) {
            pos = i;
            break;
        }
    }
    for (int i = 0; i < 5; i++) {
        bool x = (pos & (1 << i));
        send_packet(vector<bool>(31, x));
    }
    int need = 1025 - M.size() - 1;
    vector<bool> a(need, 0);
    a.push_back(1);
    for (bool x : M) {
        a.push_back(x);
    }
    int cnt = 0;
    int i = 0;
    while (cnt < 1025) {
        vector<bool> v(31);
        for (int j = 0; j < 31; j++) {
            if (i < 31 && j == pos) continue; 
            if (!C[j]) {
                v[j] = a[cnt];
                cnt++;
            }
        }
        if (i < 31) {
            v[pos] = C[i];
        }
        send_packet(v);
        i++;
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
    vector<bool> ans;
    int pos = 0;
    for (int i = 4; i >= 0; i--) {
        int sum = 0;
        for (bool x : R[i]) {
            sum += x;
        }
        pos = pos * 2 + (sum >= 16);
    }
    vector<bool> c(31);
    for (int i = 5, k = 0; i < 36; i++, k++) {
        c[k] = R[i][pos];
    }
    bool flag = false;
    for (int i = 5; i < R.size(); i++) {
        for (int j = 0; j < 31; j++) {
            if (i < 36 && j == pos) continue;
            if (!c[j]) {
                if (flag) {
                    ans.push_back(R[i][j]);
                }
                if (R[i][j]) {
                    flag = true;
                }
            }
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...