-
Notifications
You must be signed in to change notification settings - Fork 167
/
black-box-1.cpp
62 lines (57 loc) · 939 Bytes
/
black-box-1.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//black-box-1.cpp
//The Black Box
//Weekly Challenges - Week 8
//Author: derekhh
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
vector<int> vv;
int main()
{
int n;
cin >> n;
int sz = 0;
while (n--)
{
int num;
cin >> num;
if (num > 0)
{
v.push_back(num);
sz++;
}
else
{
vector<int>::iterator pos = find(v.begin(), v.end(), -num);
v.erase(pos);
sz--;
}
vv.clear();
vv = v;
sort(vv.rbegin(), vv.rend());
int sig = 1;
while (sig <= vv[0])
sig <<= 1;
sig >>= 1;
for (int t = 0; sig >= 1; sig >>= 1)
{
int i = t;
while (i < sz && (vv[i] & sig) == 0) i++;
if (i >= sz) continue;
swap(vv[t], vv[i]);
for (int j = 0; j < sz; ++j)
{
if (j != t && (vv[j] & sig) != 0)
vv[j] = vv[j] ^ vv[t];
}
t++;
}
int result = 0;
for (int q = 0; q < sz; q++)
result ^= vv[q];
printf("%d\n", result);
}
return 0;
}