Submission #599832

# Submission time Handle Problem Language Result Execution time Memory
599832 2022-07-20T01:40:35 Z yanndev Flight to the Ford (BOI22_communication) C++17
Compilation error
0 ms 0 KB
#include <communication.h>
#include <bits/stdc++.h>
using namespace std;

void encode(int n, int x) {
    if (x == 1) {
        send(1);
        send(1);
        send(1);
        send(1);
    } else if (x == 2) {
        send(0);
        send(0);
        send(0);
        send(0);
    } else {
        send(0);
        send(0);
        send(1);
        send(1);
    }
}

pair<int, int> decode(int n) {
    vector<bool> canBe (3, true);
    vector<int> bits {};
    for (int i = 0; i < 4; i++)
        bits.push_back(receive());
    
    for (int i = 0; i + 1 < 4; i++) {
        if (bits[i] == 0 && bits[i + 1] == 0) {
            hasCons0 = true;
            canBe[0] = false;
        }

        if (bits[i] == 1 && bits[i + 1] == 1) {
            canBe[1] = false;
        }
    }

    vector<int> ans {};
    for (int i = 0; i < 4; i++)
        if (canBe[i])
            ans.push_back(i + 1);
    
    if ((int)ans.size() == 1)
        return {ans[0], ans[0]};
    return {ans[0], ans[1]};
}

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:32:13: error: 'hasCons0' was not declared in this scope
   32 |             hasCons0 = true;
      |             ^~~~~~~~