Submission #635200

#TimeUsernameProblemLanguageResultExecution timeMemory
635200null_aweFlight to the Ford (BOI22_communication)C++17
0 / 100
392 ms256 KiB
#include <vector> #include <set> #include "communication.h" using namespace std; void encode(int n, int x) { set<int> todo; for (int i = 0; i < 30; ++i) todo.insert(i); int a = 0, b = 0; b |= 1; while (todo.size() > 1) { int b1 = *todo.begin(), b2 = *++todo.begin(); vector<int> res(4); res[0] = send((x >> b1) & 1); res[1] = send((x >> b2) & 1); res[2] = send((x >> b2) & 1); res[3] = send((x >> b1) & 1); if (res[1] == res[2]) { a |= res[1] << b2, b |= res[1] << b2; todo.erase(b2); } else if (res[0] == res[3]) { a -= (a & (1 << b1)), b -= (b & (1 << b1)); a |= res[0] << b1, b |= res[0] << b1, b |= 1 << b2; todo.erase(b1); } else { int pa = (res[0] == res[1]), pb = 3 - pa; 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); int a = 0, b = 0; b |= 1; while (todo.size() > 1) { int b1 = *todo.begin(), b2 = *++todo.begin(); vector<int> res(4); for (int i = 0; i < 4; ++i) res[i] = receive(); if (res[1] == res[2]) { a |= res[1] << b2, b |= res[1] << b2; todo.erase(b2); } else if (res[0] == res[3]) { a -= (a & (1 << b1)), b -= (b & (1 << b1)); a |= res[0] << b1, b |= res[0] << b1, b |= 1 << b2; todo.erase(b1); } else { int pa = (res[0] == res[1]), pb = 3 - pa; 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 {a, b}; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...