답안 #908629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908629 2024-01-16T15:38:01 Z GrandTiger1729 Flight to the Ford (BOI22_communication) C++17
0 / 100
190 ms 352 KB
#include "communication.h"
#include <bits/stdc++.h>
using namespace std;

void encode(int N, int X)
{
    int ans = 0;
    vector<int> res[2];
    int x = 0;
    res[0].push_back(0);
    for (int y = 1; y <= 29; y++)
    {
        int re[4]{};
        re[0] = send(X >> x & 1);
        re[1] = send(X >> y & 1);
        re[2] = send(X >> y & 1);
        if (re[1] == re[2])
        {
            ans ^= re[1] << y;
            continue;
        }
        re[3] = send(X >> x & 1);
        if (re[0] == re[3])
        {
            for (auto &i : res[0])
            {
                ans ^= re[0] << i;
            }
            for (auto &i : res[1])
            {
                ans ^= (!re[0]) << i;
            }
            res[0] = res[1] = vector<int>();
            res[0].push_back(y);
            x = y;
        }
        else
        {
            res[re[0] ^ re[1] ^ 1].push_back(y);
        }
    }
}

pair<int, int> decode(int N)
{
    int ans = 0;
    vector<int> res[2];
    int x = 0;
    res[0].push_back(0);
    for (int y = 1; y <= 29; y++)
    {
        int re[4]{};
        re[0] = receive();
        re[1] = receive();
        re[2] = receive();
        if (re[1] == re[2])
        {
            ans ^= re[1] << y;
            continue;
        }
        re[3] = receive();
        if (re[0] == re[3])
        {
            for (auto &i : res[0])
            {
                ans ^= re[0] << i;
            }
            for (auto &i : res[1])
            {
                ans ^= (!re[0]) << i;
            }
            res[0] = res[1] = vector<int>();
            res[0].push_back(y);
            x = y;
        }
        else
        {
            res[re[0] ^ re[1] ^ 1].push_back(y);
        }
    }
    int ans1 = ans, ans2 = ans;
    for (auto &i : res[0])
    {
        ans1 ^= 1 << i;
    }
    for (auto &i : res[1])
    {
        ans2 ^= 1 << i;
    }
    return make_pair(ans1, ans2);
}

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:48:9: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   48 |     int x = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 332 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 190 ms 352 KB Not correct
2 Halted 0 ms 0 KB -