結果
| 問題 |
No.1901 bitwise xor convolution (characteristic 2)
|
| ユーザー |
|
| 提出日時 | 2022-04-12 23:46:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 204 ms / 4,000 ms |
| コード長 | 3,705 bytes |
| コンパイル時間 | 2,224 ms |
| コンパイル使用メモリ | 126,164 KB |
| 実行使用メモリ | 61,952 KB |
| 最終ジャッジ日時 | 2024-12-22 23:26:13 |
| 合計ジャッジ時間 | 8,247 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#pragma GCC target("pclmul", "sse2", "sse4.1")
#include <emmintrin.h>
#include <smmintrin.h>
#include <wmmintrin.h>
__int64_t clmul(__int64_t x, __int64_t y) {
__m128i x_ = _mm_set_epi64x(0, x);
__m128i y_ = _mm_set_epi64x(0, y);
__m128i z_ = _mm_clmulepi64_si128(x_, y_, 0);
return _mm_extract_epi64(z_, 0);
}
using UInt = unsigned long long;
char buf[110];
UInt readPoly() {
fgets(buf, sizeof(buf), stdin);
UInt ret = 0;
for (int e = 0; e < 32; ++e) {
ret |= (UInt)(buf[e << 1] - '0') << e;
}
return ret;
}
/*
(a0 b0 + a1 b1), (a0 b1 + a1 b0)
(a0 + a1) (b0 + b1), (a0 b1 + a1 b0)
(a0 + a1) (b0 + b1), ((a0 + a1) b1 + a1 (b0 + b1))
*/
constexpr int MAX_N = 17;
int N;
UInt A[1 << MAX_N];
UInt B[1 << MAX_N];
UInt C[1 << MAX_N];
UInt zas[1 << MAX_N][MAX_N + 1];
UInt zbs[1 << MAX_N][MAX_N + 1];
UInt zcs[1 << MAX_N][MAX_N + 1];
int main() {
for (; fgets(buf, sizeof(buf), stdin); ) {
N = atoi(buf);
for (int h = 0; h < 1 << N; ++h) A[h] = readPoly();
for (int h = 0; h < 1 << N; ++h) B[h] = readPoly();
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) A[h] ^= A[h | 1 << i];
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) B[h] ^= B[h | 1 << i];
#ifdef LOCAL
memset(C, 0, sizeof(C));
memset(zas, 0, sizeof(zas));
memset(zbs, 0, sizeof(zbs));
memset(zcs, 0, sizeof(zcs));
#endif
for (int h = 0; h < 1 << N; ++h) zas[h][__builtin_popcount(h)] = A[h];
for (int h = 0; h < 1 << N; ++h) zbs[h][__builtin_popcount(h)] = B[h];
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) {
const int hh = h | 1 << i;
for (int k = 0; k <= N; ++k) zas[hh][k] ^= zas[h][k];
}
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) {
const int hh = h | 1 << i;
for (int k = 0; k <= N; ++k) zbs[hh][k] ^= zbs[h][k];
}
for (int h = 0; h < 1 << N; ++h) {
for (int k = 0; k <= N; ++k) for (int l = 0; l <= N - k; ++l) {
zcs[h][k + l] ^= clmul(zas[h][k], zbs[h][l]);
}
}
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) {
const int hh = h | 1 << i;
for (int k = 0; k <= N; ++k) zcs[hh][k] ^= zcs[h][k];
}
for (int h = 0; h < 1 << N; ++h) C[h] = zcs[h][__builtin_popcount(h)];
for (int i = 0; i < N; ++i) for (int h = 0; h < 1 << N; ++h) if (!(h & 1 << i)) C[h] ^= C[h | 1 << i];
for (int h = 0; h < 1 << N; ++h) {
for (int e = 0; e < 63; ++e) {
if (e) putchar(' ');
putchar('0' + (C[h] >> e & 1));
}
puts("");
}
}
return 0;
}