Submission #701307

# Submission time Handle Problem Language Result Execution time Memory
701307 2023-02-20T20:48:50 Z Johann Flight to the Ford (BOI22_communication) C++17
15 / 100
31 ms 1804 KB
#include "communication.h"
#include <vector>
#include <iostream>
using namespace std;

//
// --- Sample implementation for the task communication ---
//
// To compile this program with the sample grader, place:
//     communication.h communication_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
//     g++ -std=c++17 communication_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
//

typedef pair<int, int> pii;
typedef vector<int> vi;
#define sz(x) (int)(x).size()
vi messa = {0b0000, 0b1001, 0b0110, 0b1111};
vi errors = {0, 1, 2, 4, 5, 8, 9, 10};

void sendQuad(int x)
{
    for (int i = 3; i >= 0; --i)
    {
        if (messa[x] & (1 << i))
            send(1);
        else
            send(0);
    }
}
void encode(int N, int X)
{
    X = (X - 1) % 4;
    sendQuad(X);
}

pii receiveQuad()
{
    int m = 0;
    for (int i = 0; i < 4; ++i)
        m = (m << 1) | receive();
    vi ans(0);
    for (int i = 0; i < sz(messa); ++i)
    {
        for (int e : errors)
            if ((messa[i] ^ e) == m)
            {
                // cout << "Mes: " << messa[i] << " & " << e << " & " << m << endl;
                ans.push_back(i);
            }
    }
    // cout << "size of ans: " << sz(ans) << endl;
    return {ans[0], ans[1]};
}
std::pair<int, int> decode(int N)
{
    pii ans = receiveQuad();
    ++ans.first, ++ans.second;
    if (ans.second > N)
        --ans.second;
    // cout << "The Answer is: " << ans.first << " & " << ans.second << endl;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1800 KB Output is correct
2 Correct 9 ms 1804 KB Output is correct
3 Correct 19 ms 1700 KB Output is correct
4 Correct 7 ms 1708 KB Output is correct
5 Correct 13 ms 1620 KB Output is correct
6 Correct 19 ms 1740 KB Output is correct
7 Correct 31 ms 1700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 200 KB Not correct
2 Halted 0 ms 0 KB -