|
| 1 | +#define PROBLEM \ |
| 2 | + "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A" |
| 3 | +#include "../template.hpp" |
| 4 | +#include "../../../library/contest/random.hpp" |
| 5 | +#include "../../../library/math/matrix_related/xor_basis_ordered.hpp" |
| 6 | +const int B = 18; |
| 7 | +vector<bitset<B>> get_all(const vector<bitset<B>>& basis) { |
| 8 | + int n = ssize(basis); |
| 9 | + vector<bitset<B>> span; |
| 10 | + for (int mask = 0; mask < (1 << n); mask++) { |
| 11 | + bitset<B> curr_xor; |
| 12 | + assert(curr_xor.none()); |
| 13 | + for (int bit = 0; bit < n; bit++) |
| 14 | + if ((mask >> bit) & 1) curr_xor ^= basis[bit]; |
| 15 | + span.push_back(curr_xor); |
| 16 | + } |
| 17 | + ranges::sort(span, {}, [&](const bitset<B>& x) -> long { |
| 18 | + return x.to_ulong(); |
| 19 | + }); |
| 20 | + return span; |
| 21 | +} |
| 22 | +int main() { |
| 23 | + cin.tie(0)->sync_with_stdio(0); |
| 24 | + for (int num_tests = 0; num_tests < 10000; num_tests++) { |
| 25 | + xor_basis<B> b; |
| 26 | + int n = rnd(1, 18); |
| 27 | + vector<bitset<B>> naive_basis; |
| 28 | + for (int i = 0; i < n; i++) { |
| 29 | + bitset<B> val = rnd(0, (1 << n) - 1); |
| 30 | + if (b.insert(val)) naive_basis.push_back(val); |
| 31 | + } |
| 32 | + vector<bitset<B>> fast_basis; |
| 33 | + for (int i = 0; i < B; i++) |
| 34 | + if (b.basis[i].any()) |
| 35 | + fast_basis.push_back(b.basis[i]); |
| 36 | + vector<bitset<B>> naive_span = get_all(naive_basis); |
| 37 | + vector<bitset<B>> fast_span = get_all(fast_basis); |
| 38 | + assert(naive_span == fast_span); |
| 39 | + } |
| 40 | + cout << "Hello World\n"; |
| 41 | +} |
0 commit comments