From 06c33f5bedd5267eeecdd4699cca8241d12bf9d5 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Mon, 7 Oct 2024 19:11:04 +0200 Subject: [PATCH] Test for system of linear equations mod 2 + use C++23 --- .verify-helper/config.toml | 2 +- .../bitpack/system_mod_2.test.cpp | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 verify/data_structures/bitpack/system_mod_2.test.cpp diff --git a/.verify-helper/config.toml b/.verify-helper/config.toml index 40cb1f2..1ea4620 100644 --- a/.verify-helper/config.toml +++ b/.verify-helper/config.toml @@ -1,3 +1,3 @@ [[languages.cpp.environments]] CXX = "g++" -CXXFLAGS = ["-std=c++20", "-Wall", "-Wextra", "-O2", "-march=native"] +CXXFLAGS = ["-std=c++23", "-Wall", "-Wextra", "-O2", "-march=native"] diff --git a/verify/data_structures/bitpack/system_mod_2.test.cpp b/verify/data_structures/bitpack/system_mod_2.test.cpp new file mode 100644 index 0000000..84e9a06 --- /dev/null +++ b/verify/data_structures/bitpack/system_mod_2.test.cpp @@ -0,0 +1,75 @@ +// @brief System of Linear Equations (Mod 2) +#define PROBLEM "https://judge.yosupo.jp/problem/system_of_linear_equations_mod_2" +#pragma GCC optimize("Ofast,unroll-loops") +#include "cp-algo/data_structures/bitpack.hpp" +#include + +using namespace std; +using cp_algo::data_structures::bitpack; + +const int maxn = (1 << 12) + 1; +bitpack a[maxn]; + +void solve() { + int n, m; + cin >> n >> m; + string As[n]; + for(int i = 0; i < n; i++) { + cin >> As[i]; + } + string bs; + cin >> bs; + for(int i = 0; i < n; i++) { + As[i] += bs[i]; + a[i] = As[i]; + } + vector lead(n); + auto vars = views::iota(0, m + 1); + set free(begin(vars), end(vars)); + for(int i = 0; i < n; i++) { + for(int j = 0; j < i; j++) { + if(a[i][lead[j]]) { + a[i].xor_hint(a[j], lead[j]); + } + } + lead[i] = a[i].ctz(); + if(lead[i] == m) { + cout << -1 << "\n"; + return; + } + if(lead[i] > m) { + continue; + } + free.erase(lead[i]); + for(int j = 0; j < i; j++) { + if(a[j][lead[i]]) { + a[j].xor_hint(a[i], lead[i]); + } + } + } + bitpack x[maxn]; + for(auto [j, pj]: views::enumerate(free)) { + x[j].set(pj); + for(int i = 0; i < n; i++) { + if(lead[i] < m && a[i][pj]) { + x[j].set(lead[i]); + } + } + } + int rk = size(free) - 1; + swap(x[0], x[rk]); + cout << rk << "\n"; + for(int i = 0; i <= rk; i++) { + cout << x[i].to_string().substr(0, m) << "\n"; + } +} + +signed main() { + //freopen("input.txt", "r", stdin); + ios::sync_with_stdio(0); + cin.tie(0); + int t = 1; + while(t--) { + solve(); + } +}