Submission #1298000

#TimeUsernameProblemLanguageResultExecution timeMemory
1298000bangchanMessage (IOI24_message)C++20
0 / 100
138 ms804 KiB
#include "message.h"
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpl;

#define F first
#define S second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define pb push_back
#define forn(i, x, n) for (ll i = x; i < ll(n); i++)
#define fornl(i, x, n) for(ll i = x; i >= ll(n); i--)
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define inf 10000000000000

void send_message(const vector<bool> M, vector<bool> C) {
  vb a(31, 0);
  vl idx; ll cl = 0;

  forn(i, 0, 31){
    a[i] = C[i];
    if(!C[i]){cl += (i < 19); idx.pb(i);} 
    if(i < 19) send_packet(a);
  }

  if(cl > 4){
    ll h = 19;
    while(h < 31){
      a.assign(31, 0);
      ll x = 0;
      for(ll i = 0; i < cl && h < 31; i++){
        if(C[h] == 0) x++;
        a[idx[i]] = C[h]; h++;
      }
      cl += x; send_packet(a);
    }
  }

  vb b(31, 0);
  forn(i, 0, 11){
    b[idx[i]] = (b.size() & (1 << i)) != 0;
  } send_packet(b);

  ll t = 0;
  for(ll i = 0; i < (M.size() + 15) / 16; i++){ //+= 16
    ll p = 0;
    forn(j, 0, 16){
      if(p < idx.size()){
        a[idx[p]] = M[t]; p++; t++;
      }
    }
    send_packet(a);
  }
}

vector<bool> receive_message(vector<vector<bool>> R) {
  vb a; vl idx;
  forn(i, 0, 19){
    if(i < R.size()){ll qo = 0, qn = 0;
    forn(j, 0, R[i].size()){ if(R[i][j]) qo++; else qn++;}
    if(qn > qo) idx.pb(i);}
  }

  ll x = 19, act = idx.size();
  if(act > 4){
    ll h = 19;
    while(h < 31){
      act = idx.size();
      for(ll i = 0; i < act && h < 31; i++){
        if(!R[x][idx[i]]) idx.pb(h);
        h++;
      }
      x++;
    }
  } else {
    forn(j, 19, 31) idx.pb(j);
  }

  ll y = 0;
  forn(i, 0, 11) if(R[x][idx[i]]) y += (1 << i);
  x++;

  vb an(y);
  ll t = 0;
  for(ll i = 0; i < (y + 15) / 16; i++){ //+= 16
    ll p = 0;
    forn(j, 0, 16){
        if(p < idx.size() && j < an.size()){an[j] = R[x][idx[p]]; p++; t++;}
    }
    x++;
  }

  return an;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...