QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696600#9237. Messageivan_alexeev#Compile Error//C++233.3kb2024-10-31 23:45:172024-10-31 23:45:17

Judging History

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

  • [2024-10-31 23:45:17]
  • 评测
  • [2024-10-31 23:45:17]
  • 提交

answer

#include <bits/stdc++.h>
#include "message.h"

using namespace std;

#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef long long ll;


const ll inf = 1'000'000'000;

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

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


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


std::vector<bool> taint(const std::vector<bool>& A) {
  std::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;
}

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

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



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

    int S;
    assert(1 == scanf("%d", &S));
    std::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);
    std::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");
}




int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int T;
    assert(1 == scanf("%d", &T));
    for (int i = 1; i <= T; i++)
      run_scenario();
}


mt19937 rnd(239);

void send_message(vector<bool> m, vector<bool> c){
    for(int i = 0; i <= 30; i++){
        c[i] = !c[i];
    }
    int n = m.size();
    int cnt = 31;
    vector<bool> t(31, 1);
    vector<int> z;
    for(int i = 0; i <= 30; i++){
        if(c[i]){
            z.push_back(i);
        }
    }
    for(int i = 0; i <= 30; i++){
        vector<bool> s(31);
        for(auto j : z){
            s[j] = c[i];
        }
        send_packet(s);
    }
    vector<bool> m1;
    for(int i = 0; i <= 10; i++){
        m1.push_back((n >> i) & 1);
    }
    for(auto i : m){
        m1.push_back(i);
    }
    while(m1.size() % 16 != 0){
        m1.push_back(0);
    }
    for(int i = 0; i < m1.size(); i += 16){
        vector<bool> s(31);
        for(int j = 0; j < 16; j++){
            s[z[j]] = m1[i + j];
        }
        send_packet(s);
    }
}

vector<bool> receive_message(vector<vector<bool>> r){
    vector<int> c(31);
    reverse(r.begin(), r.end());
    for(int i = 0; i <= 30; i++){
        int cnt = 0;
        for(auto j : r.back()){
            cnt += j;
        }
        c[i] = (cnt >= 16);
        r.pop_back();
    }
    vector<int> z;
    for(int i = 0; i <= 30; i++){
        if(c[i]){
            z.push_back(i);
        }
    }
    vector<bool> m1;
    while(!r.empty()){
        for(int i = 0; i <= 15; i++){
            m1.push_back(r.back()[z[i]]);
        }
        r.pop_back();
    }
    int n = 0;
    for(int i = 0; i <= 10; i++){
        n += (m1[i] << i);
    }
    vector<bool> m;
    for(int i = 11; i < 11 + n; i++){
        m.push_back(m1[i]);
    }
    return m;
}

Details

answer.code: In function ‘int main()’:
answer.code:90:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:91:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccccksly.o: in function `send_packet(std::vector<bool, std::allocator<bool> >)':
stub.cpp:(.text+0x2b0): multiple definition of `send_packet(std::vector<bool, std::allocator<bool> >)'; /tmp/ccSoyQdy.o:answer.code:(.text+0x430): first defined here
/usr/bin/ld: /tmp/ccccksly.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSoyQdy.o:answer.code:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status