제출 #1353885

#제출 시각아이디문제언어결과실행 시간메모리
1353885lukaye_19Flight to the Ford (BOI22_communication)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int>data;
int i = 0;

bool randomized = false;

void send(int op)
{
    if (randomized)
    {
        data.push_back(op);
        
        randomized = false;
    }
    else
    {
        int randomness = rand();
        int r = randomness % 2;
        
        if (r)
        {
            data.push_back(1 - op);
            
            randomized = true;
        }
        else
        {
            data.push_back(op);
        }
    }
    
    //cout << data[data.size() - 1] << " " << op << " " << (randomized ? "RANDOMIZED" : "NONE") << "\n";
    
    return;
}

int receive()
{
    i++;
    
    return data[i - 1];
}

void encode(int N,int X)
{
    string binary = "";
    
    for (int i = 0; i < 30; i++)
    {
        int op = X % 2;
        
        X /= 2;
        
        binary.push_back((char)(op + '0'));
    }
    
    for (char x : binary)
    {
        int op = x - '0';
        
        if (op == 1)
        {
            send(1);
            send(0);
            send(0);
            send(1);
        }
        else if (!op)
        {
            send(0);
            send(0);
            send(0);
            send(0);
        }
    }
}

pair<int,int> decode(int N)
{
    string binary = "";
    
    for (int i = 0; i < 30; i++)
    {
        int a = receive();
        int b = receive();
        int c = receive();
        int d = receive();
        
        vector<int>v = {a,b,c,d};
        
        int X;
        
        if (v[1] == v[2])
        {
            if (v[1] == 1) X = 1;
            else X = 1;
        }
        else if (v[0] == v[3])
        {
            if (v[0] == 1) X = 1;
            else X = 0;
        }
        else if (v[0] == v[1])
        {
            X = 1;
        }
        else
        {
            X = 0;
        }
        
        X = 1 - X;
        
        binary.push_back((char)(X + '0'));
    }
    
    int R = 0;
    
    for (int i = 0; i < 30; i++)
    {
        R += (int)pow(2,i) * (binary[i] - '0');
    }
    
    return {N,R};
}

int main()
{
    srand(time(0));
    
    int N = 1e9;
    int X = 67;
    
    encode(N,X);
    pair<int,int>r = decode(N);
    
    cout << X << "\n";
    cout << r.first << " " << r.second << "\n";
}

컴파일 시 표준 에러 (stderr) 메시지

communication.cpp: In function 'void send(int)':
communication.cpp:13:9: error: reference to 'data' is ambiguous
   13 |         data.push_back(op);
      |         ^~~~
In file included from /usr/include/c++/13/string:53,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from communication.cpp:1:
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
communication.cpp:4:12: note:                 'std::vector<int> data'
    4 | vector<int>data;
      |            ^~~~
communication.cpp:24:13: error: reference to 'data' is ambiguous
   24 |             data.push_back(1 - op);
      |             ^~~~
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
communication.cpp:4:12: note:                 'std::vector<int> data'
    4 | vector<int>data;
      |            ^~~~
communication.cpp:30:13: error: reference to 'data' is ambiguous
   30 |             data.push_back(op);
      |             ^~~~
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
communication.cpp:4:12: note:                 'std::vector<int> data'
    4 | vector<int>data;
      |            ^~~~
communication.cpp: In function 'int receive()':
communication.cpp:43:12: error: reference to 'data' is ambiguous
   43 |     return data[i - 1];
      |            ^~~~
/usr/include/c++/13/bits/range_access.h:346:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  346 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:336:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  336 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:325:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  325 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:314:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  314 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
communication.cpp:4:12: note:                 'std::vector<int> data'
    4 | vector<int>data;
      |            ^~~~