Submission #635201

# Submission time Handle Problem Language Result Execution time Memory
635201 2022-08-25T16:07:23 Z null_awe Flight to the Ford (BOI22_communication) C++17
0 / 100
296 ms 200 KB
#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 {min(a, n), min(b, n)};
}
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 296 ms 200 KB Not correct
2 Halted 0 ms 0 KB -