제출 #1343694

#제출 시각아이디문제언어결과실행 시간메모리
1343694avighnaShopping (JOI21_shopping)C++20
1 / 100
62 ms12316 KiB
#include "Anna.h"
#include <bits/stdc++.h>

using namespace std;

namespace {

int N, L, R;
int cnt;

std::string str;

int width;

int ans = -1;

void check() {
  reverse(str.begin(), str.end());
  int idx = stoi(str, nullptr, 2);
  // cout << "[anna] checking idx " << idx << endl; 
  if (L <= idx && idx <= R && ans == -1) {
    ans = idx;
  }
}

} // namespace

void InitA(int N, int L, int R) {
  ::N = N;
  ::L = L;
  ::R = R;
  width = std::bit_width((unsigned)N);
  cnt = 0;

  auto send = [&](int x) {
    // cout << "!! [anna] sending " << x << endl;
    for (int bt = 0; bt < width; ++bt) {
      // cout << "[anna] sending " << !!(x & 1 << bt) << endl;
      SendA(x & 1 << bt);
    }
  };

  if (N - R < L + 1) { // send L
    // cout << "sending l\n";
    SendA(0);
    send(L);
  } else { // send R
    // cout << "sending r\n";
    SendA(1);
    send(R);
  }
  SendA(true);
}

void ReceiveA(bool x) {
  // cout << "[anna] recv " << int(x) << endl;
  str.push_back(x ? '1' : '0');
  cnt++;
  if (cnt == width) {
    check();
    str.clear();
    cnt = 0;
  }
}

int Answer() {
  return ans;
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

namespace {

int N;
int cnt;

int width;
bool is_l;
bool found_l;
int l, r;

std::vector<int> a;

std::string str;

bool FunctionExample(bool P) {
  return !P;
}

void send(int x) {
  // cout << "[bruno] sending index " << x << endl;
  for (int bt = 0; bt < width; ++bt) {
    SendB(x & 1 << bt);
  }
};

void do_work() {
  vector<int> ord(N);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) { return a[i] < a[j]; });
  for (int &i : ord) {
    if (is_l) {
      // [l, n-1]
      if (i < l) {
        continue;
      }
    } else {
      // [0, r]
      if (i > r) {
        continue;
      }
    }
    send(i);
  }
}

} // namespace

void InitB(int N, std::vector<int> P) {
  ::N = N;
  a = P;
  width = std::bit_width((unsigned)N);
  cnt = 0;
  found_l = false;
}

void ReceiveB(bool y) {
  // cout << "[bruno] recv " << int(y) << '\n';
  cnt++;
  if (cnt == 1 && !found_l) {
    found_l = 1;
    cnt = 0;
    is_l = !y;
    // cout << "[bruno] is_l = " << is_l << '\n';
    return;
  }
  str.push_back(y ? '1' : '0');
  if (cnt == width) {
    std::reverse(str.begin(), str.end());
    if (is_l) {
      l = stoi(str, nullptr, 2);
    } else {
      r = stoi(str, nullptr, 2);
    }
    do_work();
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...