Submission #1206273

#TimeUsernameProblemLanguageResultExecution timeMemory
1206273tamyteMessage (IOI24_message)C++20
0 / 100
0 ms764 KiB
#include "message.h" using namespace std; #include <bits/stdc++.h> random_device rd; mt19937 rng(rd()); const int P = 5; void send_message(std::vector<bool> M, std::vector<bool> C) { std::vector<bool> A(31, 0); vector<int> dist(31, -1); for (int i = 0; i < 31; ++i) { if (C[i] == 0) { int d = 1; for (int j = i + 1; C[j] == 1; j = (j + 1) % 31) { d++; } dist[i] = d; } } // cout << "DIST = "; // for (int i = 0; i < 31; ++i) { // cout << dist[i] << " "; // } // cout << "\n"; for (int i = 0; i < P; ++i) { for (int j = 0; j < 31; ++j) { if (C[i] == 0) { assert(dist[j] != -1); } if (dist[j] != -1) { A[j] = (dist[j] >> i) & 1; } } send_packet(A); // for (auto a : send_packet(A)) { // cout << a << " "; // } // cout << "\n"; } int bit = 0; int N = (int)M.size(); for (int i = 0; i < 31; ++i) { if (dist[i] != -1) { A[i] = (N >> bit) & 1; bit++; } } send_packet(A); bit = 0; while (bit < N) { for (int i = 0; i < 31 && bit < N; ++i) { if (dist[i] != -1) { A[i] = M[bit++]; } } send_packet(A); } } std::vector<bool> receive_message(std::vector<std::vector<bool>> R) { vector<bool> C(31); vector<int> nxt(31); for (int i = 0; i < P; ++i) { auto& v = R[i]; for (int j = 0; j < 31; ++j) { nxt[j] += (1 << i) * v[j]; } } // cout << "NXT = "; // for (int i = 0; i < 31; ++i) { // cout << nxt[i] << " "; // } // cout << "\n"; { vector<int> p(31, -1); for (int i = 0; i < 31; ++i) { p[i] = (i + nxt[i]) % 31; } map<vector<int>, int> cyc; for (int i = 0; i < 31; ++i) { vector<int> now; vector<bool> vis(31); int ni = i; while (!vis[ni]) { now.push_back(ni); vis[ni] = 1; ni = p[ni]; } sort(begin(now), end(now)); if (now.size() != 16) continue; cyc[now]++; } bool found = false; for (auto& [v, cnt] : cyc) { if (cnt == 16) { found = true; for (auto a : v) { C[a] = 1; } } } assert(found); } int siz = 0; vector<bool> res; { auto& v = R[P]; int bit = 0; for (int i = 0; i < 31; ++i) { if (C[i] == 1) { siz += (1 << bit) * v[i]; bit++; } } } // cout << "SIZE = " << siz << endl; int bit = 0; for (int i = P + 1; i < (int)R.size(); ++i) { auto& v = R[i]; for (int j = 0; j < 31; ++j) { if (bit < siz && C[j] == 1) { bit++; res.push_back(v[j]); } } } return res; } /* 5 4 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 4 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 4 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 4 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 6 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...