이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "interactive.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
#define szof(s) (int)s.size()
using namespace std;
int x;
vector <int> get_numbers(vector <int> pos) { // 2 queries
vector <int> vec1, vec2;
vec1.push_back(1);
for (int el : pos) {
vec1.push_back(el);
}
for (int el : pos) {
vec2.push_back(el);
}
map <int, int> mp;
vector <int> pairwise = get_pairwise_xor(vec1);
for (int el : pairwise) {
mp[el]++;
}
pairwise = get_pairwise_xor(vec2);
for (int el : pairwise) {
mp[el]--;
}
mp[0]--;
vector <int> numbers;
for (auto &el : mp) {
el.second /= 2;
for (int i = 1; i <= el.second; i++) {
numbers.push_back((x ^ el.first));
}
}
sort(all(numbers));
return numbers;
}
bool exist(vector <int> &vec, int x) {
return binary_search(all(vec), x);
}
vector<int> guess(int n) {
vector <int> ans;
x = ask(1);
ans.push_back(x);
if (n == 1) {
return ans;
}
vector <int> numbers;
vector <int> pos;
for (int i = 2; i <= n; i++) {
pos.push_back(i);
}
numbers = get_numbers(pos);
vector<set<int>> possible(n + 1);
for (int i = 2; i <= n; i++) {
for (int el : numbers) {
possible[i].insert(el);
}
}
for (int i = 0; i <= 7; i++) {
vector <int> mask[2];
for (int msk = 2; msk <= n; msk++) {
if (msk & (1 << i)) {
mask[1].push_back(msk);
} else {
mask[0].push_back(msk);
}
}
if (!mask[1].empty()) {
vector <int> on = get_numbers(mask[1]);
for (int pos : mask[1]) {
for (int num : numbers) {
if (!exist(on, num)) {
possible[pos].erase(num);
}
}
}
}
if (!mask[0].empty()) {
vector <int> off = get_numbers(mask[0]);
for (int pos : mask[0]) {
for (int num : numbers) {
if (!exist(off, num)) {
possible[pos].erase(num);
}
}
}
}
}
for (int i = 2; i <= n; i++) {
ans.push_back(*possible[i].begin());
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |