Submission #701314

# Submission time Handle Problem Language Result Execution time Memory
701314 2023-02-20T21:11:24 Z Johann Flight to the Ford (BOI22_communication) C++17
15 / 100
48 ms 118784 KB
#include "communication.h"
#include <vector>
#include <iostream>
#include <numeric>
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()
#define all(x) (x).begin(), (x).end()
vi messa = {0b0000, 0b1001, 0b0110, 0b1111};
vi errors = {0, 1, 2, 4, 5, 8, 9, 10};

void filterPoss(vi &poss, pii &areas)
{
    vi newPoss;
    for (int i = 0, idx; i < sz(poss); ++i)
    {
        idx = (4 * i) / sz(poss);
        if (idx == areas.first || idx == areas.second)
            newPoss.push_back(poss[i]);
    }
    swap(newPoss, poss);
}

pii evalQuad(vi &rec)
{
    int m = 0;
    for (int i = 0; i < 4; ++i)
        m = (m << 1) | rec[i];
    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]};
}
pii receiveQuad()
{
    vi rec;
    for (int i = 0; i < 4; ++i)
        rec.push_back(receive());
    return evalQuad(rec);
}
std::pair<int, int> decode(int N)
{
    vi poss(N, 0);
    iota(all(poss), 0);
    while (sz(poss) > 2)
    {
        // cout << " My Possibilies are: " << endl;
        // for (int x : poss)
        //     cout << x << endl;
        pii ans = receiveQuad();
        filterPoss(poss, ans);
    }
    if (sz(poss) == 1)
        poss.push_back(poss.front());
    ++poss[0], ++poss[1];
    // cout << "The Answer is: " << poss[0] << " & " << poss[1] << endl;
    return {poss[0], poss[1]};
}

vi sendQuad(int x)
{
    vi rec;
    for (int i = 3; i >= 0; --i)
    {
        if (messa[x] & (1 << i))
            rec.push_back(send(1));
        else
            rec.push_back(send(0));
    }
    return rec;
}
void encode(int N, int X)
{
    vi possibilities(N, 0);
    iota(all(possibilities), 0);
    --X;
    while (sz(possibilities) > 2)
    {
        // cout << "My Space is: " << endl;
        // for (int x : possibilities)
        //    cout << x << endl;
        int m = 0; // correct quarter
        for (int i = 0; i < sz(possibilities); ++i)
            if (possibilities[i] == X)
                m = (4 * i) / sz(possibilities);

        // cout << "My m is : " << m << endl;

        vi rec = sendQuad(m);
        pii ans = evalQuad(rec);
        filterPoss(possibilities, ans);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1776 KB Output is correct
2 Correct 13 ms 1780 KB Output is correct
3 Correct 17 ms 1748 KB Output is correct
4 Correct 10 ms 1680 KB Output is correct
5 Correct 15 ms 1728 KB Output is correct
6 Correct 30 ms 1788 KB Output is correct
7 Correct 36 ms 1640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 48 ms 118784 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -