Submission #172508

# Submission time Handle Problem Language Result Execution time Memory
172508 2020-01-01T19:14:38 Z emil_physmath Xoractive (IZhO19_xoractive) C++17
6 / 100
5 ms 376 KB
#include <algorithm>
#include "interactive.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef long long llong;

int ans[101];
map<int, bool> isInQ, used;

inline vector<int> Range(int l, int r)
{
    vector<int> a;
    for (int i = l; i <= r; ++i)
        a.push_back(i);
    return a;
}
inline vector<int> LeftHalf(pair<int, int> range)
{
    return Range(range.first, (range.first + range.second) / 2);
}
void Get(vector<int> ind)
{
    isInQ.clear();
    if (ind.size() == 1)
    {
        isInQ[ask(ind[0])] = true;
        return;
    }
    auto it = find(ind.begin(), ind.end(), 1);
    if (it != ind.end())
        ind.erase(it);
    vector<int> a = get_pairwise_xor(ind);
    ind.push_back(1);
    vector<int> b = get_pairwise_xor(ind);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<int> res;
    for (int i = (int)b.size() - 1; i >= 0; --i)
        if (!a.empty() && b[i] == a.back())
            a.pop_back();
        else if (b[i])
            isInQ[b[i] ^ ans[1]] = true;
    // cerr << "get({";
    // for (int i: ind) cerr << i << ", ";
    // << "})``````";
    // for (auto x: isInQ)
        // cerr << x.first << ' ';
    // cerr << endl;
}
vector<int> guess(int n)
{
    ans[1] = ask(1);
    used[ans[1]] = true;
    // Get(Range(2, n));

    /*{
        int i = 2;
        for (auto x: isInQ)
            ans[i++] = x.first;
    }*/
    // cerr << "p\n";
    // for (int i = 1; i <= n; ++i)
        // cerr << ans[i] << ' ';
    // cerr << "p\n";
    vector<pair<int, int>> lr;
    if (2 != n) lr.push_back({2, n});
    while (lr.size())
    {
        vector<int> q;
        int maxLen = 0;
        for (int i = 0; i < lr.size(); ++i)
        {
            auto temp = LeftHalf(lr[i]);
            maxLen = max(maxLen, lr[i].second - lr[i].first + 1);
            q.insert(q.end(), temp.begin(), temp.end());
        }
        // cerr << "maxLen: " << maxLen << endl;
        Get(q);
        vector<pair<int, int>> newLr;
        for (int i = 0; i < lr.size(); ++i)
        {
            // cerr << "{" << lr[i].first << ", " << lr[i].second << "}, ";
            sort(ans + lr[i].first, ans + lr[i].second + 1, [](int a, int b) {
                 return isInQ[a] > isInQ[b];
            });
            int m = (lr[i].first + lr[i].second) / 2;
            auto it = isInQ.begin();
            for (int j = lr[i].first; j <= m; ++j)
            {
                while (it != isInQ.end() && (!it->second || used[it->first]))
                    ++it;
                if (!ans[j])
                {
                    ans[j] = it->first;
                    used[ans[j]] = true;
                }
            }
            if (lr[i].first != m) newLr.push_back({lr[i].first, m});
            if (m + 1 != lr[i].second) newLr.push_back({m + 1, lr[i].second});
        }
        lr.swap(newLr);
    }
    for (int i = 1; i <= n; ++i)
        if (!ans[i])
            ans[i] = ask(i);
    return vector<int>(ans + 1, ans + n + 1);
}

Compilation message

Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:73:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < lr.size(); ++i)
                         ~~^~~~~~~~~~~
Xoractive.cpp:82:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < lr.size(); ++i)
                         ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 376 KB Output is partially correct
2 Partially correct 5 ms 376 KB Output is partially correct
3 Incorrect 5 ms 376 KB Output is not correct
4 Halted 0 ms 0 KB -