1
1
#pragma once
2
2
#include < bitset>
3
3
#include < cassert>
4
+ #include < cstddef>
4
5
#include < tuple>
5
6
#include < utility>
6
7
#include < vector>
7
8
8
9
// Gauss-Jordan elimination of n * m matrix M
9
10
// Complexity: O(nm + nm rank(M) / 64)
10
11
// Verified: abc276_h (2000 x 8000)
11
- template <int Wmax>
12
+ template <std:: size_t Wmax>
12
13
std::vector<std::bitset<Wmax>> f2_gauss_jordan (int W, std::vector<std::bitset<Wmax>> M) {
13
14
assert (W <= Wmax);
14
15
int H = M.size (), c = 0 ;
@@ -33,7 +34,8 @@ std::vector<std::bitset<Wmax>> f2_gauss_jordan(int W, std::vector<std::bitset<Wm
33
34
}
34
35
35
36
// Rank of Gauss-Jordan eliminated matrix
36
- template <int Wmax> int f2_rank_gauss_jordan (int W, const std::vector<std::bitset<Wmax>> &M) {
37
+ template <std::size_t Wmax>
38
+ int f2_rank_gauss_jordan (int W, const std::vector<std::bitset<Wmax>> &M) {
37
39
assert (W <= Wmax);
38
40
for (int h = (int )M.size () - 1 ; h >= 0 ; h--) {
39
41
int j = 0 ;
@@ -46,7 +48,7 @@ template <int Wmax> int f2_rank_gauss_jordan(int W, const std::vector<std::bitse
46
48
// determinant of F2 matrix.
47
49
// Return 0 if the matrix is singular, otherwise return 1.
48
50
// Complexity: O(W^3 / 64)
49
- template <int Wmax> int f2_determinant (const std::vector<std::bitset<Wmax>> &M) {
51
+ template <std:: size_t Wmax> int f2_determinant (const std::vector<std::bitset<Wmax>> &M) {
50
52
const int H = M.size ();
51
53
if (H > Wmax) return 0 ;
52
54
@@ -70,7 +72,7 @@ template <int Wmax> int f2_determinant(const std::vector<std::bitset<Wmax>> &M)
70
72
return 1 ; // nonsingular
71
73
}
72
74
73
- template <int W1, int W2>
75
+ template <std:: size_t W1, std:: size_t W2>
74
76
std::vector<std::bitset<W2>>
75
77
f2_matmul (const std::vector<std::bitset<W1>> &A, const std::vector<std::bitset<W2>> &B) {
76
78
int H = A.size (), K = B.size ();
@@ -83,7 +85,7 @@ f2_matmul(const std::vector<std::bitset<W1>> &A, const std::vector<std::bitset<W
83
85
return C;
84
86
}
85
87
86
- template <int Wmax>
88
+ template <std:: size_t Wmax>
87
89
std::vector<std::bitset<Wmax>> f2_matpower (std::vector<std::bitset<Wmax>> X, long long n) {
88
90
int D = X.size ();
89
91
std::vector<std::bitset<Wmax>> ret (D);
@@ -99,7 +101,7 @@ std::vector<std::bitset<Wmax>> f2_matpower(std::vector<std::bitset<Wmax>> X, lon
99
101
// - retval: {true, one of the solutions, {freedoms}} (if solution exists)
100
102
// {false, {}, {}} (otherwise)
101
103
// Complexity: O(HW + HW rank(A) / 64 + W^2 len(freedoms))
102
- template <int Wmax, class Vec >
104
+ template <std:: size_t Wmax, class Vec >
103
105
std::tuple<bool , std::bitset<Wmax>, std::vector<std::bitset<Wmax>>>
104
106
f2_system_of_linear_equations (std::vector<std::bitset<Wmax>> A, Vec b, int W) {
105
107
int H = A.size ();
0 commit comments