This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "interactive.h"
using namespace std;
int ask(int x);
vector <int> get_pairwise_xor(vector<int> v);
vector<int> guess(int n) {
vector <int> ans , q , aux , aux2;
set <int> ok[10] , s;
int p1 , bit , i , j , taken;
p1 = ask(1);
ans.push_back(p1);
for (bit = 0 ; bit <= 7 ; bit++){
q.clear();
for (i = 2 ; i <= n ; i++){
if ((i & (1 << bit)) == 0){
q.push_back(i);
}
}
aux = get_pairwise_xor(q);
q.push_back(1);
aux2 = get_pairwise_xor(q);
i = j = 0;
while (i < aux.size() && j < aux2.size()){
if (aux[i] == aux2[j]){
i++;
j++;
}
else {
if (aux2[j] != 0){
ok[bit].insert(aux2[j] ^ p1);
}
j++;
}
}
while (j < aux2.size()){
if (aux2[j] != 0){
ok[bit].insert(aux2[j] ^ p1);
}
j++;
}
}
for (i = 2 ; i <= n ; i++){
s.clear();
taken = 0;
for (bit = 0 ; bit <= 7 ; bit++){
if ( (i & (1 << bit)) == 0 ){
/// valoarea din i trb sa se regaseasca in ok[bit]
if (!taken){
for (set <int> :: iterator it = ok[bit].begin() ; it != ok[bit].end() ; it++)
s.insert(*it);
}
else {
aux.clear();
for (set <int> :: iterator it = s.begin() ; it != s.end() ; it++){
if (ok[bit].find(*it) != ok[bit].end())
aux.push_back(*it);
}
s.clear();
for (j = 0 ; j < aux.size() ; j++)
s.insert(aux[j]);
}
taken = 1;
}
}
/// -------------------------------------------------------------------------
for (bit = 0 ; bit <= 7 ; bit++){
if ( (i & (1 << bit))){
/// valoarea din i NU trb sa se regaseasca in ok[bit]
aux.clear();
for (set <int> :: iterator it = s.begin() ; it != s.end() ; it++){
if (ok[bit].find(*it) == ok[bit].end())
aux.push_back(*it);
}
s.clear();
for (j = 0 ; j < aux.size() ; j++)
s.insert(aux[j]);
}
}
if (s.size() == 1){
ans.push_back(*s.begin());
//printf ("%d %d\n" , s.size() , *s.begin());
}
else {
ans.push_back(ask(i));
//printf ("%d %d\n" , s.size() , *s.begin());
}
}
return ans;
}
Compilation message (stderr)
Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (i < aux.size() && j < aux2.size()){
| ~~^~~~~~~~~~~~
Xoractive.cpp:33:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (i < aux.size() && j < aux2.size()){
| ~~^~~~~~~~~~~~~
Xoractive.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | while (j < aux2.size()){
| ~~^~~~~~~~~~~~~
Xoractive.cpp:84:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (j = 0 ; j < aux.size() ; j++)
| ~~^~~~~~~~~~~~
Xoractive.cpp:113:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (j = 0 ; j < aux.size() ; j++)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |