Submission #603749

# Submission time Handle Problem Language Result Execution time Memory
603749 2022-07-24T10:46:10 Z Abdulmohsen1284 Flight to the Ford (BOI22_communication) C++17
0 / 100
49 ms 200 KB
#include"communication.h"
//
// --- 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
//

#include <bits/stdc++.h>
using namespace std;
void encode(int N, int X) {

    long long twos[40],n[40],x[40];
    twos[0]=1;
    for(int i=1;i<=32;i++)
        twos[i]=twos[i-1]*2;
    for(int i=1;i>=0;i--)
    {
        if(X>=twos[i])
        {
            x[i]=1;
            X-=twos[i];
        }
        else
            x[i]=0;
    }
    long long bef=send(1),rev=0,calc=1;
    for(int i=0;i<2;i++)
    {
        long long e,w;
        //cout<<x[i]<<endl<<i<<endl;
        while(calc>240)
        {
            calc=calc;
        }
        if(rev%2==0)
        {
            calc+=2;
            e=send(x[i]);
            w=send(x[i]);
        }
        else
        {
            calc+=2;
            w=send(x[i]);
            e=send(x[i]);
        }
        calc++;
        long long hg=send(1);
        if(bef==0)
        {
            bef=bef;
        }
        else if(hg==0)
        {
            hg=hg;
        }
        else if(e==w)
        {
            hg=hg;
        }
        else{
            bef=hg;
            rev++;
            i--;
            continue;
        }
        bef=hg;
    }
    //X=send(1);
}

std::pair<int, int> decode(int N) {
    //#include <bits/stdc++.h>
//using namespace std;
    long long tw[40],rev=0;
    tw[0]=1;
    for(int i=1;i<=32;i++)
        tw[i]=tw[i-1]*2;
    long long bef=-1;
    std::pair <int,int> ret;
    ret.first=0;
    ret.second=0;
    bef=receive();
    for(int i=0;i<2;i++)
    {
        //long long g=receive(),e=receive(),w=receive();
        long long e,g;
        if(rev%2==0)
        {
            g=receive();
            e=receive();
        }
        else
        {
            e=receive();
            g=receive();
        }
        long long w=receive();
        if(bef==0)
        {
            if(rev%2==0)
            ret.second+=g*tw[i];
            else
                ret.second+=e*tw[i];
        }
        else if(w==0)
        {
            if(rev%2==0)
            ret.second+=e*tw[i];
            else
            ret.second+=g*tw[i];
        }
        else if(g==e)
        {
            ret.second+=g*tw[i];
        }
        else{
            bef=w;
            rev++;
            i--;
            continue;
        }
        bef=w;
    }
    //cout<<ret.first<<" "<<ret.second;
    return ret;
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:19:24: warning: unused variable 'n' [-Wunused-variable]
   19 |     long long twos[40],n[40],x[40];
      |                        ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 200 KB Not correct
2 Halted 0 ms 0 KB -