답안 #954541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954541 2024-03-28T06:32:04 Z boris_mihov Xoractive (IZhO19_xoractive) C++17
컴파일 오류
0 ms 0 KB
#include "interactive.h"
#include <vector>
#include <map>
#include <set>

const int MAXN = 100 + 10;

std::map <int,int> map;
std::vector <int> guess(int n)
{
    std::vector <int> result(n);
    result[0] = ask(0);

    for (int bit = 0 ; (1 << bit) < n ; ++bit)
    {
        std::vector <int> v;
        for (int i = 1 ; i < n ; ++i)
        {
            if (i & (1 << bit))
            {
                v.push_back(i);
            }
        }

        std::vector <int> without = get_pairwise_xor(v); v.push_back(0);
        std::vector <int> with = get_pairwise_xor(v);
        std::multiset <int> vals;

        for (const int &val : with)
        {
            vals.insert(val);
        }

        for (const int &val : without)
        {
            vals.erase(vals.find(val));
        }

        int last = -1;
        vals.erase(vals.find(0));
        for (const int &val : vals)
        {
            if (val == last)
            {
                continue;
            }

            map[val ^ result[0]] |= (1 << bit);
            val = last;
        }
    }

    for (const auto &[key, value] : map)
    {
        result[value] = key;
    }

    return result;
}

Compilation message

Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:49:17: error: assignment of read-only reference 'val'
   49 |             val = last;
      |             ~~~~^~~~~~