File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
verify/data_structures/bitpack Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ namespace cp_algo::data_structures {
45
45
int operator [](size_t i) const {
46
46
return (data[i / bits_per_block] >> (i % bits_per_block)) & 1 ;
47
47
}
48
+ void set (size_t i) {
49
+ data[i / bits_per_block] |= 1ULL << (i % bits_per_block);
50
+ }
48
51
49
52
std::string to_string () const {
50
53
std::string res (blocks * bits_per_block, ' 0' );
Original file line number Diff line number Diff line change
1
+ // @brief Inverse Matrix (Mod 2)
2
+ #define PROBLEM " https://judge.yosupo.jp/problem/inverse_matrix_mod_2"
3
+ #pragma GCC optimize("Ofast,unroll-loops")
4
+ #include " cp-algo/data_structures/bitpack.hpp"
5
+ #include < bits/stdc++.h>
6
+
7
+ using namespace std ;
8
+ using namespace cp_algo ::data_structures;
9
+
10
+ const int maxn = 1 << 13 ;
11
+ bitpack<maxn> a[maxn];
12
+
13
+ void solve () {
14
+ int n;
15
+ cin >> n;
16
+ string row;
17
+ vector<int > lead (n);
18
+ for (int i = 0 ; i < n; i++) {
19
+ cin >> row;
20
+ a[i] = row;
21
+ a[i].set (n + i);
22
+ for (int j = 0 ; j < i; j++) {
23
+ if (a[i][lead[j]]) {
24
+ a[i].xor_hint (a[j], lead[j]);
25
+ }
26
+ }
27
+ lead[i] = a[i].ctz ();
28
+ if (lead[i] >= n) {
29
+ cout << -1 << " \n " ;
30
+ return ;
31
+ }
32
+ for (int j = 0 ; j < i; j++) {
33
+ if (a[j][lead[i]]) {
34
+ a[j].xor_hint (a[i], lead[i]);
35
+ }
36
+ }
37
+ }
38
+ for (int i = 0 ; i < n; i++) {
39
+ while (lead[i] != i) {
40
+ swap (a[i], a[lead[i]]);
41
+ swap (lead[i], lead[lead[i]]);
42
+ }
43
+ cout << a[i].to_string ().substr (n, n) << " \n " ;
44
+ }
45
+ }
46
+
47
+ signed main () {
48
+ // freopen("input.txt", "r", stdin);
49
+ ios::sync_with_stdio (0 );
50
+ cin.tie (0 );
51
+ int t = 1 ;
52
+ while (t--) {
53
+ solve ();
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments