-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2179d.cpp
More file actions
53 lines (42 loc) · 1.01 KB
/
2179d.cpp
File metadata and controls
53 lines (42 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int max_num = (1 << n) - 1;
set<int> used;
vector<int> arr;
int curr = max_num;
while(curr > 0){
if (!used.count(curr)) {
arr.push_back(curr);
used.insert(curr);
}
for(int i = curr + 1;i <= max_num;i++){
if((i&curr) == curr && !used.count(i)){
arr.push_back(i);
used.insert(i);
}
}
curr /= 2;
}
arr.push_back(0);
used.insert(0);
for(int i = 0; i < max_num;i++){
if(!used.count(i)){
arr.push_back(i);
used.insert(i);
}
}
for(auto i : arr){
cout << i << " ";
}
cout << "\n";
}
return 0;
}