Submission #1099799

# Submission time Handle Problem Language Result Execution time Memory
1099799 2024-10-12T05:20:11 Z model_code Message (IOI24_message) C++17
10 / 100
964 ms 1084 KB
// incorrect/badawy_use_known.cpp

#include "message.h"

#include <iostream>
#include <vector>
#include <algorithm>

const int LG=17, POS=31;
using namespace std;

void send(int &ind, vector<int> &kn,vector<bool> sent) {
    if(kn.size() == 0) {
        vector<bool> cur(POS, sent[ind]);
        if(sent[ind] == 0) kn.push_back(ind);
        ind++;
        send_packet(cur);
    } else {
        vector<int> tba;
        vector<bool> cur(POS);
        for(int i=0;i<kn.size();i++) {
            if(ind+i < POS && sent[ind+i] == 0) {
                tba.push_back(ind+i);
            }
            cur[kn[i]] = (ind+i < sent.size() ? sent[ind+i] : 0);
        }
        ind+=kn.size();
        send_packet(cur);
        for(int i:tba)
            kn.push_back(i);
    }
}

void send_message(std::vector<bool> message, std::vector<bool> positions) {
    vector<bool> sent;
    for(int i=0;i<positions.size();i++)
        sent.push_back(positions[i]);
    int len=message.size();
    for(int i=0;i<10;i++) sent.push_back((len>>i)&1);
    for(int i=0;i<message.size();i++)  sent.push_back(message[i]);
    vector<int> kn;
    int ind=0;
    while(ind<sent.size()) {
        send(ind, kn, sent);
    }
}

void receive(vector<int> &kn, vector<bool> &msg, vector<bool> received) {
    if(kn.size() == 0) {
        sort(received.begin(), received.end());
        msg.push_back(received[15]);
        if(msg.back() == 0) {
            kn.push_back(msg.size() - 1);
        }
    } else {
        vector<int> tba;
        for(int i=0;i<kn.size();i++) {
            msg.push_back(received[kn[i]]);
            if(msg.back()==0 && msg.size() <= POS) {
                tba.push_back(msg.size() - 1);
            }
        }
        for(int i:tba) kn.push_back(i);
    }
}

std::vector<bool> receive_message(std::vector<std::vector<bool>> received_bits) {
    vector<bool> msg;
    vector<int> kn;
    for(int i=0;i<received_bits.size();i++) receive(kn, msg, received_bits[i]);
    int len=0;
    for(int i=POS;i<POS+10;i++) len|=msg[i]<<(i-POS);
    vector<bool> rel;
    for(int i=POS+10;i<msg.size();i++) rel.push_back(msg[i]);
    while(rel.size() > len) rel.pop_back();
    return rel;
}

Compilation message

message.cpp: In function 'void send(int&, std::vector<int>&, std::vector<bool>)':
message.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int i=0;i<kn.size();i++) {
      |                     ~^~~~~~~~~~
message.cpp:25:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             cur[kn[i]] = (ind+i < sent.size() ? sent[ind+i] : 0);
      |                           ~~~~~~^~~~~~~~~~~~~
message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<positions.size();i++)
      |                 ~^~~~~~~~~~~~~~~~~
message.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<message.size();i++)  sent.push_back(message[i]);
      |                 ~^~~~~~~~~~~~~~~
message.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while(ind<sent.size()) {
      |           ~~~^~~~~~~~~~~~
message.cpp: In function 'void receive(std::vector<int>&, std::vector<bool>&, std::vector<bool>)':
message.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int i=0;i<kn.size();i++) {
      |                     ~^~~~~~~~~~
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:70:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0;i<received_bits.size();i++) receive(kn, msg, received_bits[i]);
      |                 ~^~~~~~~~~~~~~~~~~~~~~
message.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(int i=POS+10;i<msg.size();i++) rel.push_back(msg[i]);
      |                      ~^~~~~~~~~~~
message.cpp:75:22: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |     while(rel.size() > len) rel.pop_back();
      |           ~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 664 KB Used 7 days
# Verdict Execution time Memory Grader output
1 Correct 204 ms 816 KB Used 18 days
2 Correct 191 ms 812 KB Used 17 days
3 Correct 216 ms 812 KB Used 17 days
4 Correct 229 ms 828 KB Used 18 days
5 Correct 161 ms 852 KB Used 20 days
6 Correct 136 ms 852 KB Used 25 days
7 Correct 102 ms 1084 KB Used 18 days
# Verdict Execution time Memory Grader output
1 Correct 1 ms 664 KB Used 7 days
2 Correct 204 ms 816 KB Used 18 days
3 Correct 191 ms 812 KB Used 17 days
4 Correct 216 ms 812 KB Used 17 days
5 Correct 229 ms 828 KB Used 18 days
6 Correct 161 ms 852 KB Used 20 days
7 Correct 136 ms 852 KB Used 25 days
8 Correct 102 ms 1084 KB Used 18 days
9 Incorrect 964 ms 408 KB decoded message is incorrect
10 Halted 0 ms 0 KB -