forked from sarthak-2019/CP-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGaussian Elimination.cpp
More file actions
63 lines (55 loc) · 801 Bytes
/
Gaussian Elimination.cpp
File metadata and controls
63 lines (55 loc) · 801 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
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
63
struct Gauss
{
int bits = 60;
vector<int> table;
Gauss()
{
table = vector<int> (bits, 0);
}
Gauss(int _bits)
{
bits = _bits;
table = vector<int> (bits, 0);
}
int size()
{
int ans = 0;
for(int i = 0; i < bits; i++)
{
if(table[i])
ans++;
}
return ans;
}
bool can(int x)
{
for(int i = bits - 1; i >= 0; i--)
x = min(x, x ^ table[i]);
return x == 0;
}
void add(int x)
{
for(int i = bits - 1; i >= 0 && x; i--)
{
if(table[i] == 0)
{
table[i] = x;
x = 0;
}
else
x = min(x, x ^ table[i]);
}
}
int getBest()
{
int x = 0;
for(int i = bits - 1; i >= 0; i--)
x = max(x, x ^ table[i]);
return x;
}
void merge(Gauss &other)
{
for(int i = bits - 1; i >= 0; i--)
add(other.table[i]);
}
};