Submission #1099816

# Submission time Handle Problem Language Result Execution time Memory
1099816 2024-10-12T05:23:31 Z model_code Message (IOI24_message) C++17
76.1583 / 100
1067 ms 1052 KB
// partially_correct/badawy_m_7.cpp

#include "message.h"

#include <bits/stdc++.h>

using namespace std;

const int BITS=31;

int get(vector<bool> &v, int ind)
{
  if(ind<v.size()) return v[ind];
  return 0;
}

void send_message(vector<bool> message, vector<bool> positions) {
    int ind = -1;
    for(int i=0;i<positions.size();i++)
        if(positions[i]==0) {ind=i; break;}
    for(int i=0;i<5;i++) {
        vector<bool> cur(BITS, (ind&(1<<i))?1:0);
        send_packet(cur);
    }
    vector<bool> msg;
    // 5 (len) + msg.size() + 5*16 + 30 = 70 round
    int len = 0, free_bits = 30 * 15, fl;
    if(message.size() < free_bits) {
      fl=1;
      len = message.size();
    } else {
      // 5(len) msg .... 0000
      fl=0;
      len = (16-(message.size() + 5 - free_bits)%16)%16;
    }
    msg.push_back(fl);
    for(int i=0;i<(fl?10:4);i++)
      msg.push_back((len&(1<<i))?1:0);
    for(int i:message) msg.push_back(i);
    int msg_ind=0;
    for(int i=0;i<positions.size()-1;i++) {
      vector<bool> cur(BITS);
      for(int j=0;j<BITS;j++) {
        if(j == ind) {
          cur[j] = positions[i];
        }
        else if(positions[j] == 0) {
          cur[j] = get(msg, msg_ind++);
        }
      }
      send_packet(cur);
    }
    while(msg_ind < msg.size())
    {
      vector<bool> cur(BITS);
      for(int j=0;j<BITS;j++) {
        if(positions[j]==1) continue;
        cur[j] = get(msg, msg_ind++);
      }
      send_packet(cur);
    }
}

vector<bool> receive_message(vector<vector<bool>> received_bits) {
  int ind=0;
  for(int i=0;i<5;i++) {
    sort(received_bits[i].begin(), received_bits[i].end());
    ind |= (received_bits[i][15]<<i);
  }
  int rem=15;
  vector<int> positions;
  for(int i=5;i<5+30;i++) {
    positions.push_back(received_bits[i][ind]);
    rem-=positions.back();
  }
  positions.push_back(rem);
  vector<int> rcv;
  for(int i=5;i<5+30;i++) {
    for(int j=0;j<BITS;j++) {
      if(positions[j] == 0 && j != ind)
        rcv.push_back(received_bits[i][j]);
    }
  }
  for(int i=5+30;i<received_bits.size();i++) {
    for(int j=0;j<BITS;j++) {
      if(positions[j]==0) rcv.push_back(received_bits[i][j]);
    }
  }
  if(rcv[0] == 0) {
    int rem=0;
    for(int i=1;i<5;i++) rem|=(rcv[i]<<(i-1));
    while(rem--) rcv.pop_back();
    vector<bool> ret;
    for(int i=5;i<rcv.size();i++) ret.push_back(rcv[i]);
    return ret;
  } else {
    int len=0;
    for(int i=1;i<11;i++) len|=(rcv[i]<<(i-1));
    vector<bool> ret;
    for(int i=11;i<rcv.size();i++) ret.push_back(rcv[i]);
    while(ret.size() > len) ret.pop_back();
    return ret;
  }
}

Compilation message

message.cpp: In function 'int get(std::vector<bool>&, int)':
message.cpp:13:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   if(ind<v.size()) return v[ind];
      |      ~~~^~~~~~~~~
message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<positions.size();i++)
      |                 ~^~~~~~~~~~~~~~~~~
message.cpp:28:23: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     if(message.size() < free_bits) {
      |        ~~~~~~~~~~~~~~~^~~~~~~~~~~
message.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<positions.size()-1;i++) {
      |                 ~^~~~~~~~~~~~~~~~~~~
message.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     while(msg_ind < msg.size())
      |           ~~~~~~~~^~~~~~~~~~~~
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:84:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for(int i=5+30;i<received_bits.size();i++) {
      |                  ~^~~~~~~~~~~~~~~~~~~~~
message.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=5;i<rcv.size();i++) ret.push_back(rcv[i]);
      |                 ~^~~~~~~~~~~
message.cpp:100:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for(int i=11;i<rcv.size();i++) ret.push_back(rcv[i]);
      |                  ~^~~~~~~~~~~
message.cpp:101:22: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     while(ret.size() > len) ret.pop_back();
      |           ~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Used 35 days
# Verdict Execution time Memory Grader output
1 Correct 482 ms 816 KB Used 35 days
2 Correct 516 ms 820 KB Used 35 days
3 Correct 477 ms 816 KB Used 35 days
4 Correct 562 ms 988 KB Used 35 days
5 Correct 368 ms 808 KB Used 35 days
6 Correct 231 ms 812 KB Used 35 days
7 Correct 326 ms 816 KB Used 35 days
# Verdict Execution time Memory Grader output
1 Correct 2 ms 664 KB Used 35 days
2 Correct 482 ms 816 KB Used 35 days
3 Correct 516 ms 820 KB Used 35 days
4 Correct 477 ms 816 KB Used 35 days
5 Correct 562 ms 988 KB Used 35 days
6 Correct 368 ms 808 KB Used 35 days
7 Correct 231 ms 812 KB Used 35 days
8 Correct 326 ms 816 KB Used 35 days
9 Partially correct 1067 ms 832 KB Used 72 days
10 Partially correct 673 ms 832 KB Used 71 days
11 Partially correct 964 ms 840 KB Used 72 days
12 Partially correct 1028 ms 832 KB Used 71 days
13 Partially correct 965 ms 804 KB Used 71 days
14 Partially correct 706 ms 836 KB Used 72 days
15 Partially correct 500 ms 836 KB Used 72 days
16 Partially correct 693 ms 1016 KB Used 72 days
17 Partially correct 735 ms 988 KB Used 71 days
18 Correct 538 ms 824 KB Used 35 days
19 Correct 490 ms 812 KB Used 35 days
20 Correct 542 ms 812 KB Used 35 days
21 Correct 497 ms 1052 KB Used 35 days
22 Correct 516 ms 824 KB Used 39 days
23 Correct 656 ms 824 KB Used 45 days
24 Correct 622 ms 836 KB Used 51 days
25 Correct 747 ms 824 KB Used 58 days
26 Correct 853 ms 800 KB Used 64 days
27 Partially correct 857 ms 796 KB Used 70 days
28 Partially correct 964 ms 848 KB Used 72 days