Submission #635968

#TimeUsernameProblemLanguageResultExecution timeMemory
635968null_aweFlight to the Ford (BOI22_communication)C++17
0 / 100
259 ms288 KiB
#include <bits/stdc++.h> #include <communication.h> using namespace std; inline void s(int& x, int b, int v) { x -= (x & (1 << b)), x |= v << b; } void encode(int n, int x) { set<int> todo; for (int i = 0; i < 30; ++i) todo.insert(i); vector<pair<int, int>> same, diff; int a = 0, b = 0; b |= 1; while (todo.size() > 1) { int b1 = *todo.begin(), b2 = *++todo.begin(); vector<int> res(3); res[0] = send((x >> b1) & 1); res[1] = send((x >> b2) & 1); res[2] = send((x >> b2) & 1); if (res[1] == res[2]) { a |= res[1] << b2, b |= res[1] << b2; todo.erase(b2); } else { int pa = (res[0] == res[1]), pb = 3 - pa; if (pa) diff.push_back({b1, b2}); else same.push_back({b1, b2}); if (a & (1 << b1)) a |= (pb & 1) << b2; else a |= (pa & 1) << b2; if (b & (1 << b1)) b |= (pb & 1) << b2; else b |= (pa & 1) << b2; todo.erase(b1); } } } pair<int, int> decode(int n) { set<int> todo; for (int i = 0; i < 30; ++i) todo.insert(i); vector<pair<int, int>> same, diff; int a = 0, b = 0; b |= 1; while (todo.size() > 1) { int b1 = *todo.begin(), b2 = *++todo.begin(); vector<int> res(3); for (int i = 0; i < 3; ++i) res[i] = receive(); if (res[1] == res[2]) { a |= res[1] << b2, b |= res[1] << b2; todo.erase(b2); } else { int pa = (res[0] == res[1]), pb = 3 - pa; if (pa) diff.push_back({b1, b2}); else same.push_back({b1, b2}); if (a & (1 << b1)) a |= (pb & 1) << b2; else a |= (pa & 1) << b2; if (b & (1 << b1)) b |= (pb & 1) << b2; else b |= (pa & 1) << b2; todo.erase(b1); } } return {max(min(a, n), 1), max(min(b, n), 1)}; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...