답안 #505130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505130 2022-01-10T16:39:41 Z rainliofficial Xoractive (IZhO19_xoractive) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second

multiset<int> filter(vector<int>& all, vector<int>& exclude){
    multiset<int> allValues;
    for (int i : all){
        allValues.insert(all[i]);
    }
    for (int i : exclude){
        allValues.erase(allValues.find(i));
    }
    return allValues;
}
vector<int> guess(int n) {
	vector<int> ans;
	vector<int> allPositions(n);
    for (int i=0; i<n; i++){
        allPositions[i] = i+1;
    }
    vector<int> exludeFirst(n);
    for (int i=1; i<n; i++){
        allPositions[i] = i+1;
    }
    int first = ask(1);
    vector<int> allPairwiseXor = get_pairwise_xor(allPositions);
    vector<int> excludeFirstXor = get_pairwise_xor(exludeFirst);
    multiset<int> allValues = filter(allPairwiseXor, excludeFirstXor);
    vector<int> valToInd(n+1); // Maps an element to its answer index
    valToInd[first] = 1;
    // Look at answer indexes by bit
    int maxBits = log2(n)+1;
    for (int i=0; i<=maxBits; i++){  
        vector<int> currSet; // The set of numbers with this bit ON
        for (int j=2; j<=n; j++){
            if (j & (1<<i) > 0){ // This bit is ON
                currSet.push_back(j);
            }
        }
        vector<int> currSetXor = get_pairwise_xor(currSet);
        currSet.push_back(1);
        vector<int> xorWithFirst = get_pairwise_xor(currSet);
        multiset<int> currSetResult = filter(currSetXor, xorWithFirst);
        for (int i : currSetResult){
            int val = i ^ first; // Convert XOR value to orig value
            valToInd[val] += 1<<i; 
        }
    }
    for (int i=1; i<=n; i++){
        ans[valToInd[i]-1] = i;
    }
	return ans;
}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(0);

}

Compilation message

Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:28:17: error: 'ask' was not declared in this scope
   28 |     int first = ask(1);
      |                 ^~~
Xoractive.cpp:29:34: error: 'get_pairwise_xor' was not declared in this scope
   29 |     vector<int> allPairwiseXor = get_pairwise_xor(allPositions);
      |                                  ^~~~~~~~~~~~~~~~
Xoractive.cpp:39:28: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   39 |             if (j & (1<<i) > 0){ // This bit is ON
      |                     ~~~~~~~^~~