Submission #1297851

#TimeUsernameProblemLanguageResultExecution timeMemory
1297851martin_011Message (IOI24_message)C++20
0 / 100
181 ms804 KiB
#include "message.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define str string
#define vd void
#define vb vector<bool>
#define F first
#define S second
#define lbr '\n'
#define all(x) x.begin(), x.end()
const ll INF = 1E15;

vd send_message(vb m, vb c) {
  ll n = m.size();
  for (int i=0; i<30; i++) {
    bool b = c[i];
    vb a(31, b);
    send_packet(a);
  }
  ll pot = 0;
  vb mn(31, 0);
  for (int i=0; i<31; i++) {
    if (c[i]) continue;
    if ((n & (1<<pot))) mn[i]=1;
    pot++;
  }
  send_packet(mn);
  
  ll it = m.size() / 16;
  if (m.size() % 16 != 0) it++;
  ll ind = 0;
  for (int i=0; i<it; i++) {
    vb a(31, 0);
    ll j = 0;
    while (ind < n && j < 31) {
      if (c[j]) {
        j++;
        continue;
      }
      a[j] = m[ind];
      j++;
      ind++;
    }
    send_packet(a);
  }
}

vb receive_message(vector<vb> r) {
  vb c(31, 0);
  ll cr=0, us=0;
  for (int i=0; i<30; i++) {
    vll cant(2, 0);
    for (int j=0; j<31; j++) {
      cant[r[i][j]]++;
    }
    if (cant[0] > cant[1]) {
      c[i]=0;
      cr++;
    } else {
      c[i] = 1;
      us++;
    }
  }
  if (cr == us) c[30]=1;
  else c[30]=0;
  ll n = 0, pot = 0;
  for (int i=0; i<31; i++) {
    if (c[i]) continue;
    if (r[30][i]) n += (1<<pot);
    pot++;
  }
  vb res(n, 0);
  ll ind = 0;
  for (int i=31; i<r.size(); i++) {
    for (int j=0; j<31; j++) {
      if (ind==n) break;
      if (c[j]) continue;
      res[ind] = r[i][j];
      ind++;
    }
  }
  return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...