답안 #603687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603687 2022-07-24T09:47:27 Z Abdulmohsen1284 Flight to the Ford (BOI22_communication) C++17
0 / 100
617 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];
        }
    }
    for(int i=0;i<32;i++)
    {
        long long r=send(1);
        long long e=send(n[i]);
        long long w=send(n[i]);
    }
    for(int i=0;i<32;i++)
    {
        long long r=send(1),e=send(x[i]),w=send(x[i]);
    }
    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
            ret.first+=e*tw[i];
        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
            ret.second+=e*tw[i];
        bef=w;
    }
    //cout<<ret.first<<" "<<ret.second;
    return ret;
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:36:19: warning: unused variable 'r' [-Wunused-variable]
   36 |         long long r=send(1);
      |                   ^
communication.cpp:37:19: warning: unused variable 'e' [-Wunused-variable]
   37 |         long long e=send(n[i]);
      |                   ^
communication.cpp:38:19: warning: unused variable 'w' [-Wunused-variable]
   38 |         long long w=send(n[i]);
      |                   ^
communication.cpp:42:19: warning: unused variable 'r' [-Wunused-variable]
   42 |         long long r=send(1),e=send(x[i]),w=send(x[i]);
      |                   ^
communication.cpp:42:29: warning: unused variable 'e' [-Wunused-variable]
   42 |         long long r=send(1),e=send(x[i]),w=send(x[i]);
      |                             ^
communication.cpp:42:42: warning: unused variable 'w' [-Wunused-variable]
   42 |         long long r=send(1),e=send(x[i]),w=send(x[i]);
      |                                          ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 617 ms 200 KB Security violation!
2 Halted 0 ms 0 KB -