Submission #580180

# Submission time Handle Problem Language Result Execution time Memory
580180 2022-06-20T16:58:31 Z Elias Flight to the Ford (BOI22_communication) C++17
15 / 100
82 ms 1780 KB
#include <bits/stdc++.h>

#ifndef _DEBUG
#include "communication.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#endif

using namespace std;

int len = 10;
vector<int> numbers = {819, 343, 420};

#ifdef _DEBUG

void send(int x)
{
    cout << x;
}

int receive()
{
    int x;
    cin >> x;

    return x;
}

#endif

void encode(int N, int X)
{
    int number = numbers[X - 1];

    for (int i = 0; i < len; i++)
        send(bool(number & (1 << i)));
}

pair<int, int> decode(int N)
{
    int number = 0;

    for (int i = 0; i < len; i++)
    {
        number |= receive() << i;
    }

    vector<int> pos;

    for (int b = 0; b < (1 << len); b++)
    {
        bool valid = true;

        for (int i = 2; i < len; i++)
            if (b & (1 << i) && b & (1 << (i - 1)))
                valid = false;

        if (!valid)
            continue;

        int newNum = number ^ b;

        for (int i = 0; i < 3; i++)
            if (newNum == numbers[i] && !(pos.size() == 1 && pos[0] == i))
                pos.push_back(i);
    }

    while (pos.size() < 2)
        pos.push_back(0);

    return {pos[0] + 1, pos[1] + 1};
}

#ifdef _DEBUG

int main()
{
    int n;
    cin >> n;

    encode(3, n);

    cout << "\n";

    auto res = decode(3);

    cout << res.first << " " << res.second << "\n";
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1760 KB Output is correct
2 Correct 19 ms 1700 KB Output is correct
3 Correct 28 ms 1760 KB Output is correct
4 Correct 12 ms 1720 KB Output is correct
5 Correct 24 ms 1764 KB Output is correct
6 Correct 52 ms 1780 KB Output is correct
7 Correct 82 ms 1700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 328 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -