#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;
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();
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);
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;
for (int i = 0; i < lr.size(); ++i)
{
auto temp = LeftHalf(lr[i]);
q.insert(q.end(), temp.begin(), temp.end());
}
Get(q);
vector<pair<int, int>> newLr;
cerr << endl;
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;
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);
}
return vector<int>(ans + 1, ans + n + 1);
}
Compilation message
Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:66:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < lr.size(); ++i)
~~^~~~~~~~~~~
Xoractive.cpp:74:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < lr.size(); ++i)
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |