結果
| 問題 | No.1901 bitwise xor convolution (characteristic 2) |
| ユーザー |
|
| 提出日時 | 2022-04-23 15:40:50 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,544 ms / 4,000 ms |
| コード長 | 2,458 bytes |
| コンパイル時間 | 3,152 ms |
| コンパイル使用メモリ | 105,820 KB |
| 最終ジャッジ日時 | 2025-01-28 21:09:29 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using Poly = std::array<int64_t, 63>;
Poly operator+(const Poly& x, const Poly& y) {
Poly z;
for (std::size_t i = 0; i < 63; ++i) {
z[i] = x[i] + y[i];
}
return z;
}
Poly operator-(const Poly& x, const Poly& y) {
Poly z;
for (std::size_t i = 0; i < 63; ++i) {
z[i] = x[i] - y[i];
}
return z;
}
Poly operator*(const Poly& x, const Poly& y) {
std::array<int64_t, 63> dat{};
for (std::size_t i = 0; i < 32; ++i) for (std::size_t j = 0; j < 32; ++j) {
dat[i + j] += int64_t(x[i]) * int64_t(y[j]);
}
return dat;
}
void unit_walsh_hadamard_transform(Poly& x0, Poly& x1) {
Poly y0 = x0, y1 = x1;
x0 = y0 + y1; // 1, 1
x1 = y0 - y1; // 1, -1
}
template <typename UnitTransform, typename ReferenceGetter, std::size_t... Seq>
void unit_transform(UnitTransform transform, ReferenceGetter ref_getter, std::index_sequence<Seq...>) {
transform(ref_getter(Seq)...);
}
void walsh_hadamard(std::vector<Poly>& x) {
const std::size_t n = x.size();
for (std::size_t block = 1; block < n; block *= 2) {
for (std::size_t l = 0; l < n; l += 2 * block) {
for (std::size_t offset = l; offset < l + block; ++offset) {
const auto ref_getter = [&](std::size_t i) -> Poly& { return x[offset + i * block]; };
unit_transform(unit_walsh_hadamard_transform, ref_getter, std::make_index_sequence<2>());
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::size_t n;
std::cin >> n;
std::vector<Poly> a(1 << n, Poly{}), b(1 << n, Poly{}), c(1 << n, Poly{});
for (std::size_t i = 0; i < 1U << n; ++i) {
for (std::size_t j = 0; j < 32; ++j) {
std::cin >> a[i][j];
}
}
for (std::size_t i = 0; i < 1U << n; ++i) {
for (std::size_t j = 0; j < 32; ++j) {
std::cin >> b[i][j];
}
}
walsh_hadamard(a);
walsh_hadamard(b);
for (std::size_t i = 0; i < 1U << n; ++i) c[i] = a[i] * b[i];
walsh_hadamard(c);
for (std::size_t i = 0; i < 1U << n; ++i) {
for (std::size_t j = 0; j < 63; ++j) {
std::cout << ((c[i][j] >> n) & 1) << ' ';
}
std::cout << '\n';
}
return 0;
}