Submission #1359834

#TimeUsernameProblemLanguageResultExecution timeMemory
1359834dashkaShopping (JOI21_shopping)C++20
10 / 100
48 ms12256 KiB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
int N, L, R;
int cnt;
string s;
int ans;
int w;
} // namespace

void InitA(int N, int L, int R) {
    ::N = N; ::L = L; ::R = R;
    cnt = 0; ans = L;

    // bit_width(N) = ceil(log2(N+1))  -- C++17 compatible
    w = 0;
    { unsigned t = (unsigned)N; while (t > 0) { w++; t >>= 1; } }
    if (w == 0) w = 1;

    // R-г w битээр илгээнэ
    for (int i = w - 1; i >= 0; --i)
        SendA((R >> i) & 1);
}

void ReceiveA(bool x) {
    cnt++;
    s.push_back(x ? '1' : '0');
    // Bruno R-1 ширхэг бит илгээнэ (i=0..R-1 дахь suffix-min флаг)
    if (cnt == R) {
        // s[i] = 1 хэрэв P[i] нь [i..R]-н suffix minimum бол (i=0..R-1)
        // [L..R]-н хариу: s[i]=1 болох хамгийн эхний i in [L..R)
        // Хэрэв [L..R-1]-н дотор 1 байхгүй бол хариу = R
        ans = R;
        for (int i = L; i < R; ++i) {
            if (s[i] == '1') { ans = i; break; }
        }
    }
}

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

namespace {
int N, w;
vector<int> p;
int cnt;
string s;
} // namespace

void InitB(int N, std::vector<int> P) {
    ::N = N; p = P;
    w = 0;
    { unsigned t = (unsigned)N; while (t > 0) { w++; t >>= 1; } }
    if (w == 0) w = 1;
    cnt = 0;
}

void ReceiveB(bool y) {
    cnt++;
    s.push_back(y ? '1' : '0');
    if (cnt == w) {
        int R = stoi(s, nullptr, 2);
        // [0..R]-н дотроос suffix minimum флаг тооцоолно
        // sen[i] = (P[i] < min(P[i+1..R])) буюу P[i] нь [i..R]-н suffix min уу?
        // i=R: always suffix min (флаг илгээхгүй)
        // i=0..R-1: sen[i] = P[i] < suffix_min_of(i+1..R)
        vector<bool> sen;
        int cur_min = p[R];
        for (int i = R - 1; i >= 0; --i) {
            sen.push_back(p[i] < cur_min);
            if (p[i] < cur_min) cur_min = p[i];
        }
        reverse(sen.begin(), sen.end());
        // sen[0..R-1] хэмжээтэй, i=0..R-1-д тохирно
        for (auto bit : sen)
            SendB(bit);
    }
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...