Submission #1099812

# Submission time Handle Problem Language Result Execution time Memory
1099812 2024-10-12T05:22:44 Z model_code Message (IOI24_message) C++17
45.7493 / 100
1220 ms 1168 KB
// partially_correct/badawy_m_19.cpp

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

using namespace std;

const int BITS=31;

void send_message(std::vector<bool> message, std::vector<bool> positions) {
    int ind=-1;
    for(int i=0;i<BITS;i++) {
        if(positions[i] == 0 && positions[i] == positions[(i+1)%BITS]) {
            ind=i; break;
        }
    }
    for(int i=0;i<5;i++)
    {
        send_packet(vector<bool>(BITS, (ind&(1<<i))?1:0));
    }
    vector<int> npos;
    for(int i=0;i<positions.size();i++) {
        if(i==ind||i==((ind+1)%BITS)) continue;
        npos.push_back(positions[i]);
    }
    npos.pop_back();
    for(int i=0;i<npos.size()/2;i++)
    {
        vector<bool> msg(BITS,0);
        msg[ind]=npos[i*2];
        msg[(ind+1)%BITS]=npos[i*2+1];
        send_packet(msg);
    }
    int rounds = (message.size()+5+15)/16;
    int rem = (rounds*16) - (message.size()+5);
    vector<bool> sent_bits;
    for(int i=0;i<5;i++)
        sent_bits.push_back((rem&(1<<i))?1:0);
    for(int i=0;i<message.size();i++) sent_bits.push_back(message[i]);
    for(int i=0;i<rem;i++) sent_bits.push_back(0);
    vector<int> allies;
    for(int i=0;i<BITS;i++) if(positions[i] == 0) allies.push_back(i);
    for(int i=0;i<(int)sent_bits.size();i+=16) {
        vector<bool> msg(BITS);
        for(int j=0;j<16;j++) {
            msg[allies[j]] = sent_bits[i + j];
        }
        send_packet(msg);
    }
    return;
}

void add_pos(vector<bool> &pos, int v, int k1, int k2) {
    while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);
    pos.push_back(v);
    while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);

}

std::vector<bool> receive_message(std::vector<std::vector<bool>> received_bits) {
    int ind=0;
    for(int i=0;i<5;i++) {
        sort(received_bits[i].begin(), received_bits[i].end());
        if(received_bits[i][15]) ind|=(1<<i);
    }
    int co=15;
    vector<bool> positions;
    int k1=ind, k2=(ind+1)%BITS;
    for(int i=5;i<5+14;i++)
    {
        add_pos(positions, received_bits[i][ind], k1, k2);
        co-=received_bits[i][ind];
        add_pos(positions, received_bits[i][(ind+1)%BITS], k1, k2);
        co-=received_bits[i][(ind+1)%BITS];
    }
    add_pos(positions, co, k1, k2);
    vector<int> allies;
    for(int i=0;i<BITS;i++) {
        if(positions[i] == 0) allies.push_back(i);
    }
    vector<bool> sent_bits;
    for(int i=5+14;i<received_bits.size();i++) {
        for(int j:allies)
            sent_bits.push_back(received_bits[i][j]);
    }
    int rem=0;
    for(int i=0;i<5;i++) if(sent_bits[i]) rem|=(1<<i);
    vector<bool> res;
    for(int i=5;i<sent_bits.size();i++) res.push_back(sent_bits[i]);
    while(rem--) res.pop_back();
    return res;
}

Compilation message

message.cpp: In function 'void send_message(std::vector<bool>, std::vector<bool>)':
message.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<positions.size();i++) {
      |                 ~^~~~~~~~~~~~~~~~~
message.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<npos.size()/2;i++)
      |                 ~^~~~~~~~~~~~~~
message.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0;i<message.size();i++) sent_bits.push_back(message[i]);
      |                 ~^~~~~~~~~~~~~~~
message.cpp: In function 'void add_pos(std::vector<bool>&, int, int, int)':
message.cpp:54:21: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);
      |           ~~~~~~~~~~^~~~
message.cpp:54:40: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);
      |                             ~~~~~~~~~~~^~~~~
message.cpp:56:21: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |     while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);
      |           ~~~~~~~~~~^~~~
message.cpp:56:40: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |     while(pos.size()==k1 || pos.size() == k2) pos.push_back(0);
      |                             ~~~~~~~~~~~^~~~~
message.cpp: In function 'std::vector<bool> receive_message(std::vector<std::vector<bool> >)':
message.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i=5+14;i<received_bits.size();i++) {
      |                    ~^~~~~~~~~~~~~~~~~~~~~
message.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i=5;i<sent_bits.size();i++) res.push_back(sent_bits[i]);
      |                 ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 752 KB Used 20 days
# Verdict Execution time Memory Grader output
1 Correct 367 ms 812 KB Used 24 days
2 Correct 312 ms 816 KB Used 24 days
3 Correct 383 ms 1052 KB Used 24 days
4 Correct 350 ms 1048 KB Used 23 days
5 Correct 246 ms 912 KB Used 24 days
6 Correct 191 ms 816 KB Used 24 days
7 Correct 215 ms 820 KB Used 24 days
# Verdict Execution time Memory Grader output
1 Correct 1 ms 752 KB Used 20 days
2 Correct 367 ms 812 KB Used 24 days
3 Correct 312 ms 816 KB Used 24 days
4 Correct 383 ms 1052 KB Used 24 days
5 Correct 350 ms 1048 KB Used 23 days
6 Correct 246 ms 912 KB Used 24 days
7 Correct 191 ms 816 KB Used 24 days
8 Correct 215 ms 820 KB Used 24 days
9 Partially correct 1196 ms 804 KB Used 84 days
10 Partially correct 756 ms 836 KB Used 83 days
11 Partially correct 1220 ms 1056 KB Used 84 days
12 Partially correct 1189 ms 808 KB Used 83 days
13 Partially correct 1163 ms 916 KB Used 83 days
14 Partially correct 765 ms 1168 KB Used 84 days
15 Partially correct 622 ms 824 KB Used 84 days
16 Partially correct 888 ms 824 KB Used 84 days
17 Partially correct 842 ms 824 KB Used 83 days
18 Correct 333 ms 800 KB Used 26 days
19 Correct 422 ms 796 KB Used 32 days
20 Correct 502 ms 1048 KB Used 39 days
21 Correct 577 ms 816 KB Used 45 days
22 Correct 640 ms 824 KB Used 51 days
23 Correct 733 ms 1056 KB Used 57 days
24 Correct 802 ms 1060 KB Used 64 days
25 Partially correct 894 ms 1060 KB Used 70 days
26 Partially correct 1004 ms 804 KB Used 76 days
27 Partially correct 1037 ms 1056 KB Used 82 days
28 Partially correct 1154 ms 824 KB Used 84 days