File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ #include " interactive.h"
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ vector<int > guess (int n) {
6+ int k=-1 ;
7+ while (n>1 <<++k);
8+ vector<int > ans, c[k];
9+ ans.push_back (ask (1 ));
10+ for (int j=0 ; j<k; ++j) {
11+ vector<int > a;
12+ for (int i=0 ; i<n; ++i)
13+ if (i>>j&1 )
14+ a.push_back (i+1 );
15+ vector<int > b=get_pairwise_xor (a);
16+ a.push_back (1 );
17+ c[j]=get_pairwise_xor (a);
18+ c[j].erase (c[j].begin ());
19+ for (int d : b)
20+ c[j].erase (find (c[j].begin (), c[j].end (), d));
21+ for (int &d : c[j])
22+ d^=ans[0 ];
23+ }
24+ for (int i=1 ; i<n; ++i) {
25+ vector<int > v;
26+ for (int j=0 ; j<k; ++j) {
27+ if (i>>j&1 ^1 )
28+ continue ;
29+ if (v.size ()) {
30+ vector<int > w;
31+ for (int b : c[j])
32+ if (find (v.begin (), v.end (), b)!=v.end ())
33+ w.push_back (b);
34+ v=w;
35+ } else
36+ v=c[j];
37+ }
38+ for (int j=0 ; j<k; ++j)
39+ if (i>>j&1 ^1 )
40+ for (int b : c[j])
41+ if (find (v.begin (), v.end (), b)!=v.end ())
42+ v.erase (find (v.begin (), v.end (), b));
43+ ans.push_back (v[0 ]);
44+ }
45+ return ans;
46+ }
You can’t perform that action at this time.
0 commit comments