Submission #1178789

#TimeUsernameProblemLanguageResultExecution timeMemory
1178789IskachunFlight to the Ford (BOI22_communication)C++20
0 / 100
7 ms2712 KiB
#include<vector>
#include<cstdio>
#include<set>
#include<cstdlib>
#include<cstdarg>
#include<cassert>
using namespace std;

#include "communication.h"

/*
void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...)
{
    va_list args;
    va_start(args, msg);
    vfprintf(stdout, msg, args);
    fprintf(stdout, "\n");
    va_end(args);
    exit(0);
}

namespace
{
    enum { ENCODE, DECODE } current_phase;
    int N, X;
    vector<int> signals;
    size_t cursor = 0;
    bool flipped = false;
}

int send(int s)
{
    if(current_phase == DECODE or (s != 0 and s != 1))
        result("Invalid send.");

    printf("send(%d) -> ", s); fflush(stdout);
    int answer;
    if(scanf("%d", &answer) != 1 or (answer != 0 and answer != 1))
        result("Invalid reply to send.");

    bool flipped_now = (s != answer);
    if(flipped and flipped_now)
        result("Invalid reply to send");
    flipped = flipped_now;

    signals.push_back(answer);
    if(signals.size() > (size_t) 250)
        result("Looks (and smells) fishy.");
    return signals.back();
}

int receive()
{
    if(current_phase == ENCODE)  result("Invalid receive.");
    if(cursor >= signals.size()) result("Assistant waiting for Godot.");
    int r = signals[cursor++];
    printf("receive() -> %d\n", r);
    return r;
}
*/
void encode(int N, int x) {
    if (x == 1) {
        int a = send(0), b = send(0);
        while (a or b) a = b, b = send(0);
    } else {
        int a = send(1), b = send(1);
        while (!a or !b) a = b, b = send(1);
    }
}

pair<int, int> decode(int N) {
    int a = receive(), b = receive();
    while ((a and !b) or (!a and b)) a = b, b = receive();
    if (a and b) return {2, 3};
    else return {1, 2};
}

/*
int main()
{
    if(scanf("%d %d", &N, &X) != 2 or X < 1 or X > N)
        result("Invalid input.");

    current_phase = ENCODE;
    encode(N, X);
    current_phase = DECODE;
    auto r = decode(N);

    if(r.first < 1 or r.first > N or r.second < 1 or r.second > N)
        result("Invalid answer.");

    if(r.first == X or r.second == X)
        result("Correct: %d signals sent.", (int) signals.size());
    else
        result("Wrong answer.");
}
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...