結果

問題 No.2907 Business Revealing Dora Tiles
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-09-27 20:39:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 11,551 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 135,264 KB
実行使用メモリ 814,916 KB
最終ジャッジ日時 2024-09-27 20:39:30
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
9,984 KB
testcase_01 AC 10 ms
9,984 KB
testcase_02 AC 10 ms
10,304 KB
testcase_03 AC 10 ms
10,240 KB
testcase_04 AC 9 ms
10,180 KB
testcase_05 AC 9 ms
9,984 KB
testcase_06 AC 12 ms
11,520 KB
testcase_07 AC 10 ms
9,984 KB
testcase_08 AC 10 ms
10,112 KB
testcase_09 AC 10 ms
10,112 KB
testcase_10 AC 8 ms
10,060 KB
testcase_11 AC 34 ms
27,520 KB
testcase_12 AC 11 ms
10,312 KB
testcase_13 AC 9 ms
10,112 KB
testcase_14 AC 10 ms
10,112 KB
testcase_15 AC 9 ms
10,240 KB
testcase_16 AC 9 ms
9,984 KB
testcase_17 AC 10 ms
10,112 KB
testcase_18 AC 15 ms
14,660 KB
testcase_19 AC 9 ms
10,112 KB
testcase_20 AC 10 ms
10,112 KB
testcase_21 AC 74 ms
65,920 KB
testcase_22 AC 35 ms
28,660 KB
testcase_23 MLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#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> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
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; }
#define COLOR(s) ("\x1b[" s "m")


////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


#ifndef LIBRA_ALGEBRA_NIMBER_H_
#define LIBRA_ALGEBRA_NIMBER_H_

#include <assert.h>

////////////////////////////////////////////////////////////////////////////////
namespace nim {
using u16 = unsigned short;
using u32 = unsigned;
using u64 = unsigned long long;

// G16: primitive root in F_(2^16)
// G16\^3 = 2^15
constexpr u16 G16 = 10279U;
u16 expBuffer[4 * (1 << 16) + 4];
u16 *exp = expBuffer + (2 * (1 << 16) + 4), *exp3 = exp + 3, *exp6 = exp + 6;
int log[1 << 16];
u64 tabSq[4][1 << 16], tabSqrt[4][1 << 16], tabSolveQuad1[4][1 << 16];

// L: power of 2
// (a0 + 2^l a1) \* (b0 + 2^l b1)
// = (a0\*b0 \+ 2^(l-1)\*a1\*b1) + 2^l (a0\*b1 \+ a1\*b0 \+ a1\*b1)
template <int L> inline u64 mulSlow(u64 a, u64 b) {
  static constexpr int l = L >> 1;
  const u64 a0 = a & ((1ULL << l) - 1), a1 = a >> l;
  const u64 b0 = b & ((1ULL << l) - 1), b1 = b >> l;
  const u64 a0b0 = mulSlow<l>(a0, b0);
  return (a0b0 ^ mulSlow<l>(1ULL << (l - 1), mulSlow<l>(a1, b1)))
      | (a0b0 ^ mulSlow<l>(a0 ^ a1, b0 ^ b1)) << l;
}
template <> inline u64 mulSlow<1>(u64 a, u64 b) {
  return a & b;
}

// 2^31 \* a
inline u32 mul31(u32 a) {
  const u16 a0 = a, a1 = a >> 16;
  const u16 a01 = a0 ^ a1;
  return exp6[log[a1]] | (u32)exp3[log[a01]] << 16;
}

inline u16 mul(u16 a, u16 b) {
  return exp[log[a] + log[b]];
}
inline u32 mul(u32 a, u32 b) {
  const u16 a0 = a, a1 = a >> 16;
  const u16 b0 = b, b1 = b >> 16;
  const u16 a01 = a0 ^ a1;
  const u16 b01 = b0 ^ b1;
  const u16 a0b0 = mul(a0, b0);
  return (a0b0 ^ exp3[log[a1] + log[b1]]) | (u32)(a0b0 ^ mul(a01, b01)) << 16;
}
inline u64 mul(u64 a, u64 b) {
  const u32 a0 = a, a1 = a >> 32;
  const u32 b0 = b, b1 = b >> 32;
  const u32 a01 = a0 ^ a1;
  const u32 b01 = b0 ^ b1;
  const u32 a0b0 = mul(a0, b0);
  return (a0b0 ^ mul31(mul(a1, b1))) | (u64)(a0b0 ^ mul(a01, b01)) << 32;
}

inline u16 sq(u16 a) {
  return tabSq[0][a];
}
inline u32 sq(u32 a) {
  const u16 a0 = a, a1 = a >> 16;
  return tabSq[0][a0] ^ tabSq[1][a1];
}
inline u64 sq(u64 a) {
  const u16 a0 = a, a1 = a >> 16, a2 = a >> 32, a3 = a >> 48;
  return tabSq[0][a0] ^ tabSq[1][a1] ^ tabSq[2][a2] ^ tabSq[3][a3];
}

inline u16 sqrt(u16 a) {
  return tabSqrt[0][a];
}
inline u32 sqrt(u32 a) {
  const u16 a0 = a, a1 = a >> 16;
  return tabSqrt[0][a0] ^ tabSqrt[1][a1];
}
inline u64 sqrt(u64 a) {
  const u16 a0 = a, a1 = a >> 16, a2 = a >> 32, a3 = a >> 48;
  return tabSqrt[0][a0] ^ tabSqrt[1][a1] ^ tabSqrt[2][a2] ^ tabSqrt[3][a3];
}

// (a0 + 2^l a1) \* (b0 + 2^l b1) = 1
// <=> [ a0  2^(l-1)\*a1 ] \* [ b0 ] = [ 1 ]
//     [ a1  a0\+a1      ]    [ b1 ]   [ 0 ]
inline u16 inv(u16 a) {
  assert(a);
  return exp[((1 << 16) - 1) - log[a]];
}
inline u32 inv(u32 a) {
  assert(a);
  const u16 a0 = a, a1 = a >> 16;
  const u16 a01 = a0 ^ a1;
  const u16 d = inv((u16)(mul(a0, a01) ^ exp3[log[a1] + log[a1]]));
  return mul(d, a01) | (u32)mul(d, a1) << 16;
}
inline u64 inv(u64 a) {
  assert(a);
  const u32 a0 = a, a1 = a >> 32;
  const u32 a01 = a0 ^ a1;
  const u32 d = inv(mul(a0, a01) ^ mul31(sq(a1)));
  return mul(d, a01) | (u64)mul(d, a1) << 32;
}

// f(x) := x\^2 \+ x
// bsr(x\^2) = bsr(x)
// f: {even in [0, 2^L)} -> [0, 2^(L-1)): linear isom.
// f(x0 + 2^l x1) = (f(x0) \+ 2^(l-1)\*x1\^2) + 2^l f(x1)
template <int L> inline u64 solveQuad1Slow(u64 a) {
  static constexpr int l = L >> 1;
  assert(!(a >> (L - 1)));
  const u64 a0 = a & ((1ULL << l) - 1), a1 = a >> l;
  const u64 x1 = solveQuad1Slow<l>(a1);
  const u64 b0 = a0 ^ mul(1ULL << (l - 1), sq(x1));
  const u64 s = b0 >> (l - 1);
  return solveQuad1Slow<l>(b0 ^ s << (l - 1)) | (x1 ^ s) << l;
}
template <> inline u64 solveQuad1Slow<1>(u64 a) {
  assert(!a);
  return 0;
}

// x\^2 \+ x \+ a = 0
// solutions: x, x \+ 1
inline u64 solveQuad1(u64 a) {
  assert(!(a >> 63));
  const u16 a0 = a, a1 = a >> 16, a2 = a >> 32, a3 = a >> 48;
  return tabSolveQuad1[0][a0] ^ tabSolveQuad1[1][a1] ^ tabSolveQuad1[2][a2] ^ tabSolveQuad1[3][a3];
}

// x\^2 \+ a\*x \+ b = 0
// solutions: x, x \+ a
inline bool isSolvableQuad(u64 a, u64 b) {
  return !(mul(inv(sq(a)), b) >> 63);
}
inline u64 solveQuad(u64 a, u64 b) {
  return a ? mul(a, solveQuad1(mul(inv(sq(a)), b))) : sqrt(b);
}

struct Preparator {
  Preparator() {
    exp[0] = 1;
    for (int i = 1; i < (1 << 16) - 1; ++i) exp[i] = mulSlow<16>(exp[i - 1], G16);
    for (int i = (1 << 16) - 1; i < 2 * (1 << 16); ++i) exp[i] = exp[i - ((1 << 16) - 1)];
    for (int i = 0; i < (1 << 16) - 1; ++i) log[exp[i]] = i;
    log[0] = -(1 << 16) - 2;
    for (int e = 0; e < 64; ++e) {
      const u64 x = mul(1ULL << e, 1ULL << e);
      for (int i = 0; i < 1 << (e & 15); ++i) tabSq[e >> 4][i | 1 << (e & 15)] = tabSq[e >> 4][i] ^ x;
    }
    for (int e = 0; e < 64; ++e) {
      u64 x = 1ULL << e;
      for (int j = 0; j < 63; ++j) x = sq(x);
      for (int i = 0; i < 1 << (e & 15); ++i) tabSqrt[e >> 4][i | 1 << (e & 15)] = tabSqrt[e >> 4][i] ^ x;
    }
    for (int e = 0; e < 63; ++e) {
      const u64 x = solveQuad1Slow<64>(1ULL << e);
      for (int i = 0; i < 1 << (e & 15); ++i) tabSolveQuad1[e >> 4][i | 1 << (e & 15)] = tabSolveQuad1[e >> 4][i] ^ x;
    }
  }
} preparator;
}  // namespace nim
////////////////////////////////////////////////////////////////////////////////

#endif  // LIBRA_ALGEBRA_NIMBER_H_


struct Nim64 {
  unsigned long long x;
  constexpr Nim64() : x(0ULL) {}
  constexpr Nim64(unsigned x_) : x(x_) {}
  constexpr Nim64(unsigned long long x_) : x(x_) {}
  constexpr Nim64(int x_) : x(x_) {}
  constexpr Nim64(long long x_) : x(x_) {}
  Nim64 &operator+=(const Nim64 &a) { x ^= a.x; return *this; }
  Nim64 &operator-=(const Nim64 &a) { x ^= a.x; return *this; }
  Nim64 &operator*=(const Nim64 &a) { x = nim::mul(x, a.x); return *this; }
  // TODO: operator/=, pow, inv
  Nim64 operator+() const { return *this; }
  Nim64 operator-() const { return *this; }
  Nim64 operator+(const Nim64 &a) const { return (Nim64(*this) += a); }
  Nim64 operator-(const Nim64 &a) const { return (Nim64(*this) -= a); }
  Nim64 operator*(const Nim64 &a) const { return (Nim64(*this) *= a); }
  // TODO: operator/
  explicit operator bool() const { return x; }
  bool operator==(const Nim64 &a) const { return (x == a.x); }
  bool operator!=(const Nim64 &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const Nim64 &a) { return os << a.x; }
};


int M, N;
Nim64 A[20][20];

int main() {
  /*
  using namespace nim;
  cerr << (mul(3ULL - 1, 12ULL - 1) ^ mul(6ULL - 1, 2ULL - 1) ^ mul(9ULL - 1, 2ULL - 1)) << endl;
  cerr << (mul(5ULL - 1, 12ULL - 1) ^ mul(10ULL - 1, 2ULL - 1) ^ mul(15ULL - 1, 2ULL - 1)) << endl;
  */
  
  for (; ~scanf("%d%d", &N, &M); ) {
    for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) {
      scanf("%llu", &A[i][j].x);
      --A[i][j].x;
    }
    
    vector<int> rs(1 << N);
    vector<vector<vector<Nim64>>> as(1 << N);
    rs[0] = 0;
    as[0] = vector<vector<Nim64>>(M, vector<Nim64>(N));
    for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) as[0][i][j] = A[i][j];
    for (int h = 0; h < N; ++h) {
      for (int p = 0; p < 1 << h; ++p) {
        int &r = rs[p | 1 << h] = rs[p];
        auto &a = as[p | 1 << h] = as[p];
        for (int i = r; i < M; ++i) if (a[i][h]) {
          swap(a[r], a[i]);
          break;
        }
        if (r < M && a[r][h]) {
          const Nim64 s = nim::inv(a[r][h].x);
          for (int j = h + 1; j < N; ++j) a[r][j] *= s;
          for (int i = r + 1; i < M; ++i) for (int j = h + 1; j < N; ++j) a[i][j] -= a[i][h] * a[r][j];
          ++r;
        }
      }
    }
// cerr<<"rs = "<<rs<<endl;
    
    Mint ans = 0;
    for (int p = 0; p < 1 << N; ++p) {
      const int n = __builtin_popcount(p);
      ans += ((N-n)&1?-1:+1) * Mint(2).pow(64).pow(n - rs[p]);
    }
    printf("%u\n", ans.x);
  }
  return 0;
}
0