Submission #1353850

#TimeUsernameProblemLanguageResultExecution timeMemory
1353850lukaye_19Flight to the Ford (BOI22_communication)C++20
0 / 100
90 ms2880 KiB
#include "communication.h"
#include <bits/stdc++.h>
using namespace std;

void encode(int N,int X)
{
    string binary = "";
    
    for (int i = 0; i < 30; i++)
    {
        int op = X % 2;
        
        X /= 2;
        
        binary.push_back((char)(op + '0'));
    }
    
    for (char x : binary)
    {
        int op = x - '0';
        
        if (op == 1)
        {
            send(1);
            send(0);
            send(0);
            send(1);
        }
        else
        {
            send(0);
            send(0);
            send(0);
            send(0);
        }
    }
}

pair<int,int> decode(int N)
{
    string binary = "";
    
    for (int i = 0; i < 30; i++)
    {
        int a = receive();
        int b = receive();
        int c = receive();
        int d = receive();
        
        vector<int>v = {a,b,c,d};
        
        int X;
        
        if (v[0] == v[3])
        {
            if (v[0] == 1) X = 2;
            else X = 1;
        }
        else if (v[0] == v[1])
        {
            X = 2;
        }
        else
        {
            X = 1;
        }
        
        X--;
        
        binary.push_back((char)(X + '0'));
    }
    
    int R = 0;
    
    for (int i = 0; i < 30; i++)
    {
        R += (int)pow(2,i) * (binary[i] - '0');
    }
    
    return {N,R};
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...