結果

問題 No.1901 bitwise xor convolution (characteristic 2)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-12 21:52:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 939 ms / 4,000 ms
コード長 3,639 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 127,092 KB
実行使用メモリ 62,028 KB
最終ジャッジ日時 2024-06-01 04:47:40
合計ジャッジ時間 8,818 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,064 KB
testcase_01 AC 4 ms
11,848 KB
testcase_02 AC 4 ms
9,936 KB
testcase_03 AC 3 ms
9,808 KB
testcase_04 AC 3 ms
9,808 KB
testcase_05 AC 3 ms
9,808 KB
testcase_06 AC 3 ms
9,680 KB
testcase_07 AC 922 ms
62,028 KB
testcase_08 AC 939 ms
62,020 KB
testcase_09 AC 925 ms
62,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

UInt readPoly() {
  UInt ret = 0;
  for (int e = 0; e < 32; ++e) {
    int x;
    scanf("%d", &x);
    ret |= ((UInt)x) << 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 (; ~scanf("%d", &N); ) {
    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;
}
0