Submission #603727

# Submission time Handle Problem Language Result Execution time Memory
603727 2022-07-24T10:28:34 Z Abdulmohsen1284 Flight to the Ford (BOI22_communication) C++17
0 / 100
85 ms 236 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(N>=twos[i])
        {
            n[i]=1;
            N-=twos[i];
        }
        else
            n[i]=0;
        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++)
    {
        //if(bef==-1)
        //long long bef=send(1);
        //cout<<n[i]<<endl<<i<<endl;
        long long e,w;
        while(calc>240)
        {
            calc=calc;
        }
        if(rev%2==0)
        {
            calc+=2;
            e=send(n[i]);
            w=send(n[i]);
        }
        else
        {
            calc+=2;
            w=send(n[i]);
            e=send(n[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{
            rev++;
            i--;
            continue;
        }
        bef=hg;
    }
    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{
            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 e,g;
        if(rev%2==0)
        {
            g=receive();
            e=receive();
        }
        else
        {
            e=receive();
            g=receive();
        }
        long long w=receive();
        if(bef==0)
        {
            ret.first+=g*tw[i];
        }
        else if(w==0)
        {
            ret.first+=e*tw[i];
        }
        else if(g==e)
        {
            ret.first+=g*tw[i];
        }
        else{
            rev++;
            i--;
            continue;
        }
        bef=w;
    }
    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)
        {
            ret.second+=g*tw[i];
        }
        else if(w==0)
        {
            ret.second+=e*tw[i];
        }
        else if(g==e)
        {
            ret.second+=g*tw[i];
        }
        else{
            rev++;
            i--;
            continue;
        }
        bef=w;
    }
    long long st=ret.first,en=ret.second;
    //cout<<ret.first<<" "<<ret.second;
    return ret;
}

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:208:15: warning: unused variable 'st' [-Wunused-variable]
  208 |     long long st=ret.first,en=ret.second;
      |               ^~
communication.cpp:208:28: warning: unused variable 'en' [-Wunused-variable]
  208 |     long long st=ret.first,en=ret.second;
      |                            ^~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 236 KB Not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 200 KB Not correct
2 Halted 0 ms 0 KB -