Submission #1194433

#TimeUsernameProblemLanguageResultExecution timeMemory
1194433NeltMessage (IOI24_message)C++20
72.85 / 100
399 ms868 KiB
#include "message.h"
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
using namespace std;
ll cost(vector<bool> &c)
{
    ll tot = 0;
    ll ptr = 0, sz = 0;
    while (sz < 16)
    {
        tot++;
        for (ll i = 0; i < sz and ptr < 31 and sz < 16; i++, ptr++)
            sz += c[ptr] == 0;
        if ((16 - sz) * 2 > 31 - ptr)
        {
            if (c[ptr] == 0)
                sz++;
            ptr++;
        }
    }
    return tot;
}
void send_message(vector<bool> a, vector<bool> c)
{
    vector<bool> msg(31, 0), revc = c;
    reverse(revc.begin(), revc.end());
    bool flg = cost(revc) < cost(c);
    send_packet(vector<bool>(31, cost(revc) < cost(c)));
    if (flg)
        swap(revc, c);
    vector<ll> fixed;
    ll ptr = 0;
    while (fixed.size() < 16)
    {
        for (ll i = 0; i < fixed.size() and ptr < 31; i++, ptr++)
        {
            msg[fixed[i]] = c[ptr];
            if (c[ptr] == 0)
                fixed.push_back(flg ? 30 - ptr : ptr);
        }
        if ((16 - fixed.size()) * 2 > 31 - ptr)
        {
            for (ll i = (flg ? 0 : ptr); i <= (flg ? 30 - ptr : 30); i++)
                msg[i] = c[ptr];
            if (c[ptr] == 0)
                fixed.push_back(flg ? 30 - ptr : ptr);
            ptr++;
        }
        send_packet(msg);
    }
    if (fixed.size() != 16)
        exit(0);
    for (ll i = 0; i < 16; i++)
        msg[fixed[i]] = (a.size() >> i & 1);
    send_packet(msg);
    for (ll i = 0; i < a.size(); i += 16)
    {
        for (ll j = 0; j + i < a.size() and j < 16; j++)
            msg[fixed[j]] = a[i + j];
        send_packet(msg);
    }
}
bool majority(vector<bool> &c, ll l, ll r)
{
    return count(c.begin() + l, c.begin() + r + 1, 1) * 2 > (r - l + 1);
}
vector<bool> receive_message(vector<vector<bool>> a)
{
    vector<bool> c(31, 1);
    bool flg = majority(a[0], 0, 30);
    ll ptr = 0, cur = 1;
    vector<ll> fixed;
    while (fixed.size() < 16)
    {
        for (ll i = 0; i < fixed.size() and ptr < 31; i++, ptr++)
        {
            c[ptr] = a[cur][fixed[i]];
            if (c[ptr] == 0)
                fixed.push_back(flg ? 30 - ptr : ptr);
        }
        if ((16 - fixed.size()) * 2 > 31 - ptr)
        {
            c[ptr] = majority(a[cur], flg ? 0 : ptr, flg ? 30 - ptr : 30);
            if (c[ptr] == 0)
                fixed.push_back(flg ? 30 - ptr : ptr);
            ptr++;
        }
        cur++;
    }
    if (fixed.size() != 16)
        exit(0);
    ll sz = 0;
    for (ll i = 0; i < 16; i++)
        if (a[cur][fixed[i]])
            sz += 1 << i;
    vector<bool> ans(sz);
    for (ll i = 0; i < sz; i++)
        ans[i] = a[cur + 1 + (i >> 4)][fixed[i & 15]];
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...