Submission #635989

# Submission time Handle Problem Language Result Execution time Memory
635989 2022-08-27T13:53:10 Z null_awe Flight to the Ford (BOI22_communication) C++17
0 / 100
205 ms 200 KB
#include <bits/stdc++.h>
#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 = 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 (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 = 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 (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 time Memory Grader output
1 Incorrect 37 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 205 ms 200 KB Not correct
2 Halted 0 ms 0 KB -