답안 #603700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603700 2022-07-24T09:54:37 Z Abdulmohsen1284 Flight to the Ford (BOI22_communication) C++17
0 / 100
3 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;
long long twos[40],n[40],x[40];
void encode(int N, int X) {
    twos[0]=1;
    for(int i=1;i<=32;i++)
        twos[i]=twos[i-1]*2;
    for(int i=32;i>=0;i--)
    {
        if(N>=twos[i])
        {
            n[i]=1;
            N-=twos[i];
        }
        if(X>=twos[i])
        {
            x[i]=1;
            X-=twos[i];
        }
    }
    long long bef=-1;
    for(int i=0;i<32;i++)
    {
        if(bef==-1)
        long long bef=send(1);
        long long e=send(n[i]);
        long long w=send(n[i]);
        long long hg=send(1);
        if(bef==0)
        {
            bef=bef;
        }
        else if(hg==0)
        {
            hg=hg;
        }
        else if(e==w)
        {
            hg=hg;
        }
        else{
            i--;
            continue;
        }
        bef=hg;
    }
    for(int i=0;i<32;i++)
    {
        long long e=send(x[i]),w=send(x[i]),hg=send(1);
        if(bef==0)
        {
            bef=bef;
        }
        else if(hg==0)
        {
            hg=hg;
        }
        else if(e==w)
        {
            hg=hg;
        }
        else{
            i--;
            continue;
        }
        bef=hg;
    }
    X=send(1);
}

std::pair<int, int> decode(int N) {
    long long tw[40];
    tw[0]=1;
    for(int i=1;i<=32;i++)
        tw[i]=tw[i-1]*2;
    long long bef=-1;
    pair <int,int> ret;
    ret.first=0;
    ret.second=0;
    bef=receive();
    for(int i=0;i<32;i++)
    {
        long long g=receive(),e=receive(),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{
            i--;
            continue;
        }
        bef=w;
    }
    for(int i=0;i<32;i++)
    {
        //long long g=receive(),e=receive(),w=receive();
        long long g=receive(),e=receive(),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{
            i--;
            continue;
        }
        bef=w;
    }
    //cout<<ret.first<<" "<<ret.second;
    return ret;
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:38:19: warning: unused variable 'bef' [-Wunused-variable]
   38 |         long long bef=send(1);
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 200 KB Not correct
2 Halted 0 ms 0 KB -