Submission #181958

# Submission time Handle Problem Language Result Execution time Memory
181958 2020-01-09T11:10:40 Z stefdasca Xoractive (IZhO19_xoractive) C++14
6 / 100
7 ms 376 KB
#include "interactive.h"
#include<bits/stdc++.h>
using namespace std;

int n, xorr[12], sol[102], val[102];
vector<int> query[12];
/*
int ask(int poz)
{
    return val[poz];
}
vector<int> get_pairwise_xor(vector<int> poz)
{
    vector<int> ans;
    for(int i = 0; i < poz.size(); ++i)
        for(int j = 0; j < poz.size(); ++j)
            ans.push_back(val[poz[i]] ^ val[poz[j]]);
    sort(ans.begin(), ans.end());
    return ans;
}

*/
int process(vector<int> v)
{
    int occ = 1;
    int cv = v[0];
    int ans = 0;
    for(int i = 1; i < v.size(); ++i)
    {
        if(v[i] == v[i-1])
            ++occ;
        else
        {
            occ /= 2;
            if(occ & 1)
                ans ^= cv;
            occ = 1;
            cv = v[i];
        }
    }
    occ /= 2;
    if(occ & 1)
        ans ^= cv;
    return ans;
}
vector<int> guess(int n)
{
    int nr = 1;
    for(int i = n; i >= 1; --i)
        query[nr].push_back(i);
    vector<int> xors = get_pairwise_xor(query[1]);
    xorr[nr] = process(xors);
  //  cout << xorr[1] << '\n';
    for(int bit = 0; (1<<bit) <= n; ++bit)
    {
        ++nr;
        for(int i = n; i >= 1; --i)
            if(i & (1<<bit))
                query[nr].push_back(i);
        if(query[nr].size() == 1)
            xorr[nr] = ask(query[nr][0]);
        else
            xorr[nr] = process(get_pairwise_xor(query[nr]));
      //  cout << xorr[nr] << '\n';
    }
    for(int i = 1; i <= n; ++i)
    {
        if((i & (i-1)) == 0)
            sol[i] = ask(i);
        else
        {
            int orr = 0;
            for(int j = 2; j <= nr; ++j)
                if(!(i & (1<<(j-2))))
                    orr |= xorr[j];
           // cout << i << " " << xorr[1] << " " << orr << '\n';
            sol[i] = (xorr[1] ^ orr);
        }
        xorr[1] ^= sol[i];
        for(int j = 2; j <= nr; ++j)
            if(i & (1<<(j-2)))
                xorr[j] ^= sol[i];
      //  for(int j = 1; j <= nr; ++j)
       //     cout << xorr[j] << " ";
      //  cout << '\n';
    }
    vector<int>ans;
    for(int i = 1; i <= n; ++i)
        ans.push_back(sol[i]);
    return ans;
}
/*
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> val[i];
    vector<int> sol = guess(n);
    for(int i = 0; i < n; ++i)
        cout << sol[i] << " ";
    return 0;
}
*/

Compilation message

Xoractive.cpp: In function 'int process(std::vector<int>)':
Xoractive.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < v.size(); ++i)
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 7 ms 256 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Output is not correct
2 Halted 0 ms 0 KB -