-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathc.cc
More file actions
34 lines (31 loc) · 711 Bytes
/
c.cc
File metadata and controls
34 lines (31 loc) · 711 Bytes
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
// https://codeforces.com/contest/1300/problem/C
#include <bits/stdc++.h>
using namespace std;
int bits[32];
int main() {
cin.tie(0), ios::sync_with_stdio(0);
int n, m;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
m = 1;
for (int j = 0; j < 32; j++, m *= 2)
if (a[i] & m) {
if (!bits[j]) bits[j] = i + 1;
else bits[j] = -1;
}
}
vector<int> r, s(n);
for (int j = 31; j >= 0; j--) {
if (bits[j] > 0 && !s[bits[j]-1]) {
r.push_back(bits[j]-1);
s[bits[j]-1] = 1;
}
}
for (int i = 0; i < n; i++)
if (!s[i])
r.push_back(i);
for (int i = 0; i < n; i++)
cout << a[r[i]] << " \n"[i == n - 1];
}