QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562025#9237. MessageZanite#0 169ms3968kbC++205.7kb2024-09-13 14:22:162024-09-13 14:22:16

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 14:22:16]
  • 评测
  • 测评结果:0
  • 用时:169ms
  • 内存:3968kb
  • [2024-09-13 14:22:16]
  • 提交

answer

#include "message.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define All(x)   x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"

template<typename T> bool chmax(T &u, T v) { if (u < v) { u = v; return true; } return false; }

template<typename T>
ostream& operator<<(ostream& os, const vector<T> &v) {
    os << "["; bool _first = true;
    for (auto i : v) { if (!_first) { os << ", "; } os << i; _first = false; }
    return os << "]";
}

const ll INF = 1'000'000'000'000'000'000;

const int PKT_SIZE  = 31;
const int FREE_IDX  = 16;
const int CLEO_IDX  = 15;
const int M_SZ_BITS = 10;
const int F_ID_BITS = 5;

void send_message(vector<bool> M, vector<bool> C) {
    int S = M.size();
    vector<int> free_indices;
    for (int i = 0; i < PKT_SIZE; i++) if (!C[i]) free_indices.push_back(i);

    // Transmit all indices status
    int transmitted      = 0;
    int transmitted_free = 0;
    int transmitted_cleo = 0;
    while (transmitted < PKT_SIZE) {
        if (transmitted_free == FREE_IDX) break;
        if (transmitted_cleo == CLEO_IDX) {
            while (transmitted < PKT_SIZE) free_indices.push_back(transmitted++);
        }

        vector<bool> cur(PKT_SIZE);
        if (!transmitted_free) {
            if (C[transmitted] == 1) transmitted_cleo++;
            else transmitted_free++;
            cur = vector<bool>(PKT_SIZE, C[transmitted++]);
        } else {
            int prv_free = transmitted_free;
            for (int i = 0; i < prv_free; i++) {
                if (transmitted < PKT_SIZE) {
                    if (C[transmitted] == 1) transmitted_cleo++;
                    else transmitted_free++;
                    cur[free_indices[i]] = C[transmitted++];
                }
            }
        }

        // cerr << transmitted << "\n";

        send_packet(cur);
    }
    
    vector<bool> T;
    for (int i = 0; i < M_SZ_BITS; i++) T.push_back((S-1) & (1 << i));
    for (auto i : M) T.push_back(i);

    int ptr = 0;
    while (ptr < (int)T.size()) {
        vector<bool> cur(PKT_SIZE);
        for (auto idx : free_indices) if (ptr < (int)T.size()) {
            cur[idx] = T[ptr++];
        }
        send_packet(cur);
    }
}

vector<bool> receive_message(vector<vector<bool>> R) {
    int read_packets = 0;

    vector<int> free_indices;
    int transmitted      = 0;
    int transmitted_free = 0;
    int transmitted_cleo = 0;
    while (transmitted < PKT_SIZE) {
        if (transmitted_free == FREE_IDX) break;
        if (transmitted_cleo == CLEO_IDX) {
            while (transmitted < PKT_SIZE) free_indices.push_back(transmitted++);
        }

        vector<bool> cur_packet = R[read_packets++];
        if (!transmitted_free) {
            int c0 = count(cur_packet.begin(), cur_packet.end(), 0);
            int c1 = count(cur_packet.begin(), cur_packet.end(), 1);

            bool cur = ((c0 < c1) ? 1 : 0);
            // debug(cur);
            if (cur == 1) transmitted_cleo++;
            else { transmitted_free++; free_indices.push_back(transmitted); }
            transmitted++;

        } else {
            int prv_free = transmitted_free;
            for (int i = 0; i < prv_free; i++) {
                if (transmitted < PKT_SIZE) {
                    bool cur = cur_packet[free_indices[i]];
                    // debug(cur);
                    if (cur == 1) transmitted_cleo++;
                    else { transmitted_free++; free_indices.push_back(transmitted); }
                    transmitted++;
                }
            }
        }

        // cerr << transmitted << "\n";
    }

    // debug(free_indices);

    vector<bool> tv;
    while (read_packets < (int)R.size()) {
        vector<bool> cur_packet = R[read_packets++];
        for (auto j : free_indices) tv.push_back(cur_packet[j]);
    }

    int sz = 0;
    for (int i = 0; i < M_SZ_BITS; i++) if (tv[i]) {
        sz |= (1 << i);
    }
    sz++;

    vector<bool> ans;
    for (int i = M_SZ_BITS; i < M_SZ_BITS + sz; i++) ans.push_back(tv[i]);

    return ans;
}

#ifdef Zanite

namespace {
const int PACKET_SIZE = 31;
const int CALLS_CNT_LIMIT = 100;

int calls_cnt;
vector<bool> C(PACKET_SIZE);
vector<vector<bool>> R;

void quit(const char* message) {
    printf("%s\n", message);
    exit(0);
}

void run_scenario() {
    R.clear();
    calls_cnt = 0;

    int S;
    assert(1 == scanf("%d", &S));
    vector<bool> M(S);
    for (int i = 0; i < S; i++) {
        int bit;
        assert(1 == scanf("%d", &bit));
        assert((bit == 0) || (bit == 1));
        M[i] = bit;
    }

    for (int i = 0; i < PACKET_SIZE; i++) {
        int bit;
        assert(1 == scanf("%d", &bit));
        assert((bit == 0) || (bit == 1));
        C[i] = bit;
    }

    send_message(M, C);
    vector<bool> D = receive_message(R);

    int K = (int)R.size();
    int L = (int)D.size();
    printf("%d %d\n", K, L);
    for (int i = 0; i < L; i++)
        printf("%s%d", (i == 0 ? "" : " "), (D[i] ? 1 : 0));
    printf("\n");
}

vector<bool> taint(const vector<bool>& A) {
    vector<bool> B = A;
    bool bit = 0;
    for (int i = 0; i < PACKET_SIZE; i++)
        if (C[i] == 1) {
            B[i] = bit;
            bit = !bit;
        }
    return B;
}

} // namespace

vector<bool> send_packet(vector<bool> A) {
    calls_cnt++;
    if (calls_cnt > CALLS_CNT_LIMIT)
        quit("Too many calls");
    if ((int)A.size() != PACKET_SIZE)
        quit("Invalid argument");

    vector<bool> B = taint(A);
    R.push_back(B);
    return B;
}

int main() {
    int T;
    assert(1 == scanf("%d", &T));
    for (int i = 1; i <= T; i++)
        run_scenario();
}

#endif

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 53ms
memory: 3968kb

Manager to Aisha


Aisha to Manager


Manager to Basma


Basma to Manager


Manager to Checker

0
ing with message 'decoded message is incorrect'
Sending secret with code DIE to mgr2sol[1]
Quitting with result code 1

result:

wrong output format Extra information in the output file

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 169ms
memory: 3800kb

Manager to Aisha


Aisha to Manager


Manager to Basma


Basma to Manager


Manager to Checker

0
ing with message 'decoded message is incorrect'
Sending secret with code DIE to mgr2sol[1]
Quitting with result code 1

result:

wrong output format Extra information in the output file