-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA.cpp
41 lines (40 loc) · 747 Bytes
/
A.cpp
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
#include "bits/stdc++.h"
using namespace std;
int cnt[40];
int a[100010];
const int logn = 32;
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
for(int j = 0; j < logn; j++) {
cnt[j] += ((a[i] >> j) & 1);
}
}
int opt = 0;
int id = 1;
for(int i = 1; i <= n; i++) {
int num = 0;
for(int j = 0; j < logn; j++) {
cnt[j] -= ((a[i] >> j) & 1);
if(cnt[j] > 0) {
num ^= 1 << j;
}
}
if(opt < ((a[i] | num) - num)) {
opt = (a[i] | num) - num;
id = i;
}
for(int j = 0; j < logn; j++) {
cnt[j] += ((a[i] >> j) & 1);
}
}
printf("%d ", a[id]);
for(int i = 1; i <= n; i++) {
if(i != id) printf("%d ", a[i]);
}
printf("\n");
return 0;
}