結果

問題 No.1901 bitwise xor convolution (characteristic 2)
ユーザー 👑 Nachia
提出日時 2026-04-10 23:24:33
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 634 ms / 4,000 ms
コード長 2,666 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 781 ms
コンパイル使用メモリ 109,404 KB
実行使用メモリ 80,328 KB
最終ジャッジ日時 2026-04-10 23:24:46
合計ジャッジ時間 7,577 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }

#include <smmintrin.h>
#include <wmmintrin.h>


struct Mint {
    using u64 = unsigned long long;
    u64 x;
    
    #pragma GCC target("pclmul")
    #pragma GCC target("sse4.1")
    static u64 mul(u64 a, u64 b){
        __m128i ab = _mm_set_epi64x(a, b);
        __m128i xy = _mm_clmulepi64_si128(ab, ab, 1);
        return _mm_extract_epi64(xy, 0);
    }

    using Self = Mint;
    Mint(u64 v=0) : x(v) {}
    Self operator+(const Self& r) const { return Self(x ^ r.x); }
    Self operator-(const Self& r) const { return Self(x ^ r.x); }
    Self operator*(const Self& r) const { return Self(mul(x, r.x)); }
    Self& operator+=(const Self& r){ x ^= r.x; return *this; }
    Self& operator-=(const Self& r){ x ^= r.x; return *this; }
    Self& operator*=(const Self& r){ x = mul(x, r.x); return *this; }
    Self operator-() const { return Self(x); }
};

V<V<Mint>> expand(int N, V<Mint>& a){
  V<V<Mint>> A(N+1, V<Mint>(1<<N));
  REP(i,1<<N) A[__builtin_popcount(i)][i] = a[i];
  for(auto& h : A) REP(d,N) REP(i,1<<N) if(!(i&1<<d)) h[i|1<<d] += h[i];
  return A;
}
V<Mint> contract(int N, V<V<Mint>>& A){
  for(auto& h : A) REP(d,N) REP(i,1<<N) if(!(i&1<<d)) h[i|1<<d] -= h[i];
  V<Mint> a(1<<N);
  REP(i,1<<N){
    int v = __builtin_popcount(i);
    a[i] = A[v][i];
  }
  return a;
}

Mint get32(){
  unsigned long long x = 0;
  for(int i=0; i<32; i++){
    char c; cin >> c;
    x |= (unsigned long long)(c - '0') << i;
  }
  return Mint(x);
}

void testcase(){
  int N; cin >> N;
  V<Mint> A(1<<N); REP(i,1<<N){ A[i] = get32(); }
  V<Mint> B(1<<N); REP(i,1<<N){ B[i] = get32(); }
  V<Mint> C(1<<N);
  REP(d,N) REP(i,1<<N) if(!(i&1<<d)) A[i] -= A[i|1<<d];
  REP(d,N) REP(i,1<<N) if(!(i&1<<d)) B[i] -= B[i|1<<d];
  V<V<Mint>> AA = expand(N, A), BB = expand(N, B);
  V<V<Mint>> CC(N*2+1, V<Mint>(1<<N));
  REP(a,N+1) REP(b,N+1) REP(i,1<<N) CC[a+b][i] += AA[a][i] * BB[b][i];
  C = contract(N, CC);
  REP(d,N) REP(i,1<<N) if(!(i&1<<d)) C[i] += C[i|1<<d];
  REP(i,1<<N){
    auto val = C[i].x;
    for(int d=0; d<=62; d++){
      if(d) cout << ' ';
      cout << char('0' + (val >> d & 1));
    }
    cout << "\n";
  }
}

int main(){
  cin.tie(0)->sync_with_stdio(0);
  testcase();
  return 0;
}
0