Submission #1335509

#TimeUsernameProblemLanguageResultExecution timeMemory
1335509windowwifeMessage (IOI24_message)C++20
100 / 100
386 ms860 KiB
#ifndef rtgsp
#include "message.h"
#endif // rtgsp

#include<bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 1e6 + 4;

#ifdef rtgsp
vector<bool> C;
vector<vector<bool>> uwu;
mt19937_64 rd(0);
vector<bool> send_packet (vector<bool> A)
{
    for (int i = 0; i < 31; i++)
        if (C[i])
        {
            A[i] = uniform_int_distribution<int>(0, 1)(rd);
        }
    uwu.push_back(A);
    return A;
}
#endif // rtgsp

vector<int> pos;
vector<vector<bool>> msg;

void send_message (vector<bool> M, vector<bool> C)
{
    int ok = (int)M.size() - 1;
    while ((int)M.size() < 1025) M.push_back(M[ok] ^ 1);
    pos.clear();
    for (int i = 0; i < 31; i++)
        if (C[i] == 0) pos.push_back(i);
    msg.clear();
    for (int i = 0; i < 66; i++)
        msg.push_back(vector<bool>(31, 0));
    for (int i = 0, cur = 0; i < 16; i++)
    {
        int dist = (pos[(i + 1) % 16] - pos[i] + 31) % 31;
        msg[dist - 1][pos[i]] = 1;
        while (dist < 66)
        {
            msg[dist++][pos[i]] = M[cur++];
        }
    }
    for (int i = 0; i < 66; i++)
        send_packet(msg[i]);
}

int p[maxn], deg[maxn];
queue<int> q;
vector<bool> ans;

vector<bool> receive_message (vector<vector<bool>> R)
{
    ans.clear();
    for (int i = 0; i < 31; i++)
    {
        deg[i] = 0;
        p[i] = i;
        for (int j = 0; j < 16; j++)
        {
            if (R[j][i])
            {
                p[i] = (i + j + 1) % 31;
                break;
            }
        }
    }
    for (int i = 0; i < 31; i++)
    {
        ++deg[p[i]];
    }
    for (int i = 0; i < 31; i++)
    {
        if (deg[i] == 0) q.push(i);
    }
    while (!q.empty())
    {
        int i = q.front();
        q.pop();
        if (--deg[p[i]] == 0) q.push(p[i]);
    }
    for (int i = 0; i < 31; i++)
    {
        if (deg[i] == 0) continue;
        pos.clear();
        int j = p[i], cnt = 1;
        pos.push_back(i);
        while (j != i)
        {
            ++cnt;
            pos.push_back(j);
            j = p[j];
        }
        if (cnt == 16) break;
    }
    for (int i = 0; i < 16; i++)
    {
        for (int j = (pos[(i + 1) % 16] - pos[i] + 31) % 31; j < 66; j++)
        {
            ans.push_back(R[j][pos[i]]);
        }
    }
    bool lol = ans.back();
    while (ans.back() == lol) ans.pop_back();
    return ans;
}

#ifdef rtgsp
int main ()
{
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<bool>> a[n];
    vector<int> gp;
    for (int i = 0; i < n; i++)
        gp.push_back(i);
    shuffle(gp.begin(), gp.end(), rd);
    for (int i = 0; i < n; i++) cerr << gp[i] << " ";
    cerr << '\n';
    for (int i = 0; i < n; i++)
    {
        cerr << "test " << i << endl;
        C.clear();
        C.resize(31, 0);
        vector<int> P;
        P.clear();
        P.resize(31, 0);
        for (int i = 0; i < 31; i++)
            P[i] = i;
        shuffle(P.begin(), P.end(), rd);
        for (int i = 0; i < 15; i++)
            C[P[i]] = 1;
        for (int i = 0; i < 31; i++)
            cerr << C[i];
        cerr << endl;
        uwu.clear();
        vector<bool> M;
        M.clear();
        for (int i = 0; i < 5; i++)
        {
            M.push_back(uniform_int_distribution<int>(0, 1)(rd));
            cerr << M[i];
        }
        cerr << endl;
        send_message(M, C);
        a[gp[i]] = uwu;
    }
    for (int i = 0; i < n; i++)
    {
        cout << "decode " << i << endl;
        auto v = receive_message(a[i]);
        for (bool b : v) cerr << b;
        cerr << endl;
    }
}
#endif // rtgsp

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...