Skip to content

Commit 06c33f5

Browse files
committed
Test for system of linear equations mod 2 + use C++23
1 parent f4a2f5d commit 06c33f5

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

.verify-helper/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[[languages.cpp.environments]]
22
CXX = "g++"
3-
CXXFLAGS = ["-std=c++20", "-Wall", "-Wextra", "-O2", "-march=native"]
3+
CXXFLAGS = ["-std=c++23", "-Wall", "-Wextra", "-O2", "-march=native"]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// @brief System of Linear Equations (Mod 2)
2+
#define PROBLEM "https://judge.yosupo.jp/problem/system_of_linear_equations_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 cp_algo::data_structures::bitpack;
9+
10+
const int maxn = (1 << 12) + 1;
11+
bitpack<maxn> a[maxn];
12+
13+
void solve() {
14+
int n, m;
15+
cin >> n >> m;
16+
string As[n];
17+
for(int i = 0; i < n; i++) {
18+
cin >> As[i];
19+
}
20+
string bs;
21+
cin >> bs;
22+
for(int i = 0; i < n; i++) {
23+
As[i] += bs[i];
24+
a[i] = As[i];
25+
}
26+
vector<int> lead(n);
27+
auto vars = views::iota(0, m + 1);
28+
set<int> free(begin(vars), end(vars));
29+
for(int i = 0; i < n; i++) {
30+
for(int j = 0; j < i; j++) {
31+
if(a[i][lead[j]]) {
32+
a[i].xor_hint(a[j], lead[j]);
33+
}
34+
}
35+
lead[i] = a[i].ctz();
36+
if(lead[i] == m) {
37+
cout << -1 << "\n";
38+
return;
39+
}
40+
if(lead[i] > m) {
41+
continue;
42+
}
43+
free.erase(lead[i]);
44+
for(int j = 0; j < i; j++) {
45+
if(a[j][lead[i]]) {
46+
a[j].xor_hint(a[i], lead[i]);
47+
}
48+
}
49+
}
50+
bitpack<maxn> x[maxn];
51+
for(auto [j, pj]: views::enumerate(free)) {
52+
x[j].set(pj);
53+
for(int i = 0; i < n; i++) {
54+
if(lead[i] < m && a[i][pj]) {
55+
x[j].set(lead[i]);
56+
}
57+
}
58+
}
59+
int rk = size(free) - 1;
60+
swap(x[0], x[rk]);
61+
cout << rk << "\n";
62+
for(int i = 0; i <= rk; i++) {
63+
cout << x[i].to_string().substr(0, m) << "\n";
64+
}
65+
}
66+
67+
signed main() {
68+
//freopen("input.txt", "r", stdin);
69+
ios::sync_with_stdio(0);
70+
cin.tie(0);
71+
int t = 1;
72+
while(t--) {
73+
solve();
74+
}
75+
}

0 commit comments

Comments
 (0)