Submission #601108

# Submission time Handle Problem Language Result Execution time Memory
601108 2022-07-21T11:21:29 Z alextodoran Flight to the Ford (BOI22_communication) C++17
0 / 100
42 ms 1848 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

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

using namespace std;

typedef long long ll;

const int SEED = 3000;
const int W_MAX = 5;

int send (int s);
void encode (int N, int X) {
    mt19937 rnd(SEED);
    N--; X--;
    while (N > 0) {
        int w;
        int bit = X % 2;
        bool lied = false;
        int cnt = 0;
        while (true) {
            if (cnt % W_MAX == 0) {
                w = rnd() % (W_MAX - 1) + 1;
            }
            cnt++;
            int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
            if (send(r[bit]) != r[!bit]) {
                if (lied == true) {
                    break;
                }
                lied = true;
            } else {
                lied = false;
            }
        }
        N /= 2;
        X /= 2;
    }
}

int receive ();
pair <int, int> decode (int N) {
    mt19937 rnd(SEED);
    N--;
    int X = 0;
    int k = 0;
    while (N > 0) {
        int w;
        bool lied[] = {false, false};
        int cnt = 0;
        while (true) {
            if (cnt % W_MAX == 0) {
                w = rnd() % (W_MAX - 1) + 1;
            }
            cnt++;
            int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
            int rec = receive();
            bool stop = false;
            for (int bit : {0, 1}) {
                if (rec != r[bit]) {
                    if (lied[bit] == true) {
                        X |= (!bit << k);
                        stop = true;
                        break;
                    }
                    lied[bit] = true;
                } else {
                    lied[bit] = false;
                }
            }
            if (stop == true) {
                break;
            }
        }
        N /= 2;
        k++;
    }
    X++;
    return make_pair(X, X);
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:33:39: warning: comparison of integer expressions of different signedness: 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                         ~~~~~~~~~~~~~~^~~
communication.cpp:33:60: warning: comparison of integer expressions of different signedness: 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                                              ~~~~~~~~~~~~~~^~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:63:39: warning: comparison of integer expressions of different signedness: 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                         ~~~~~~~~~~~~~~^~~
communication.cpp:63:60: warning: comparison of integer expressions of different signedness: 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                                              ~~~~~~~~~~~~~~^~~
communication.cpp: In function 'void encode(int, int)':
communication.cpp:33:41: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                                         ^
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:63:41: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |             int r[] = {(rnd() % W_MAX < w), (rnd() % W_MAX < w)};
      |                                         ^
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1680 KB Output is correct
2 Correct 42 ms 1848 KB Output is correct
3 Correct 37 ms 1728 KB Output is correct
4 Correct 25 ms 1688 KB Output is correct
5 Correct 28 ms 1708 KB Output is correct
6 Incorrect 5 ms 200 KB Not correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 200 KB Not correct
2 Halted 0 ms 0 KB -