結果

問題 No.2159 Filling 4x4 array
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-12-11 02:29:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 6,474 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 112,976 KB
実行使用メモリ 4,532 KB
最終ジャッジ日時 2023-08-05 04:20:48
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
4,492 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 32 ms
4,376 KB
testcase_03 AC 32 ms
4,416 KB
testcase_04 AC 33 ms
4,376 KB
testcase_05 AC 32 ms
4,376 KB
testcase_06 AC 32 ms
4,380 KB
testcase_07 AC 32 ms
4,376 KB
testcase_08 AC 32 ms
4,532 KB
testcase_09 AC 33 ms
4,532 KB
testcase_10 AC 32 ms
4,376 KB
testcase_11 AC 32 ms
4,376 KB
testcase_12 AC 32 ms
4,416 KB
testcase_13 AC 32 ms
4,380 KB
testcase_14 AC 32 ms
4,376 KB
testcase_15 AC 32 ms
4,380 KB
testcase_16 AC 33 ms
4,376 KB
testcase_17 AC 32 ms
4,380 KB
testcase_18 AC 32 ms
4,380 KB
testcase_19 AC 32 ms
4,376 KB
testcase_20 AC 32 ms
4,420 KB
testcase_21 AC 33 ms
4,376 KB
testcase_22 AC 33 ms
4,384 KB
testcase_23 AC 33 ms
4,480 KB
testcase_24 AC 32 ms
4,380 KB
testcase_25 AC 32 ms
4,376 KB
testcase_26 AC 33 ms
4,380 KB
testcase_27 AC 32 ms
4,416 KB
testcase_28 AC 32 ms
4,376 KB
testcase_29 AC 32 ms
4,376 KB
testcase_30 AC 32 ms
4,376 KB
testcase_31 AC 32 ms
4,380 KB
testcase_32 AC 33 ms
4,376 KB
testcase_33 AC 33 ms
4,380 KB
testcase_34 AC 32 ms
4,424 KB
testcase_35 AC 32 ms
4,380 KB
testcase_36 AC 33 ms
4,380 KB
testcase_37 AC 32 ms
4,376 KB
testcase_38 AC 32 ms
4,504 KB
testcase_39 AC 32 ms
4,376 KB
testcase_40 AC 32 ms
4,376 KB
testcase_41 AC 32 ms
4,380 KB
testcase_42 AC 33 ms
4,376 KB
testcase_43 AC 32 ms
4,380 KB
testcase_44 AC 32 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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

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

Mint f0[4][4][4][4][4][4][4];
Mint f1[4][4][4][4][5][5][5];
Mint f2[4][4][4][4][6][6][6];
Mint f3[4][4][4][4][7][7][7];

#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  Int A[4], B[4];
  for (; ~scanf("%lld", &A[0]); ) {
    for (int x = 1; x < 4; ++x) scanf("%lld", &A[x]);
    for (int y = 0; y < 4; ++y) scanf("%lld", &B[y]);
    for (int x = 0; x < 4; ++x) A[x] -= 4;
    for (int y = 0; y < 4; ++y) B[y] -= 4;
    
    Mint ans = 0;
    if (A[0] + A[1] + A[2] + A[3] == B[0] + B[1] + B[2] + B[3]) {
      memset(f0, 0, sizeof(f0));
      f0[0][0][0][0][0][0][0] = 1;
      for (int e = 0; e < 30; ++e) {
        int as[4], bs[4];
        for (int x = 0; x < 4; ++x) as[x] = A[x] >> e & 1;
        for (int y = 0; y < 4; ++y) bs[y] = B[y] >> e & 1;
        memset(f1, 0, sizeof(f1));
        rep(x0, 4) rep(x1, 4) rep(x2, 4) rep(x3, 4) {
          rep(z0, 2) rep(z1, 2) rep(z2, 2) rep(z3, 2) {
            const int s = x0 + (z0 + z1 + z2 + z3);
            if ((s & 1) == as[0]) {
              rep(y0, 4) rep(y1, 4) rep(y2, 4) {
                f1[s >> 1][x1][x2][x3][y0 + z0][y1 + z1][y2 + z2] += f0[x0][x1][x2][x3][y0][y1][y2];
              }
            }
          }
        }
        memset(f2, 0, sizeof(f2));
        rep(x0, 4) rep(x1, 4) rep(x2, 4) rep(x3, 4) {
          rep(z0, 2) rep(z1, 2) rep(z2, 2) rep(z3, 2) {
            const int s = x1 + (z0 + z1 + z2 + z3);
            if ((s & 1) == as[1]) {
              rep(y0, 5) rep(y1, 5) rep(y2, 5) {
                f2[x0][s >> 1][x2][x3][y0 + z0][y1 + z1][y2 + z2] += f1[x0][x1][x2][x3][y0][y1][y2];
              }
            }
          }
        }
        memset(f3, 0, sizeof(f3));
        rep(x0, 4) rep(x1, 4) rep(x2, 4) rep(x3, 4) {
          rep(z0, 2) rep(z1, 2) rep(z2, 2) rep(z3, 2) {
            const int s = x2 + (z0 + z1 + z2 + z3);
            if ((s & 1) == as[2]) {
              rep(y0, 6) rep(y1, 6) rep(y2, 6) {
                f3[x0][x1][s >> 1][x3][y0 + z0][y1 + z1][y2 + z2] += f2[x0][x1][x2][x3][y0][y1][y2];
              }
            }
          }
        }
        memset(f0, 0, sizeof(f0));
        rep(x0, 4) rep(x1, 4) rep(x2, 4) rep(x3, 4) {
          rep(z0, 2) rep(z1, 2) rep(z2, 2) rep(z3, 2) {
            const int s = x3 + (z0 + z1 + z2 + z3);
            if ((s & 1) == as[3]) {
              for (int y0 = (bs[0] - z0) & 1; y0 < 7; y0 += 2)
              for (int y1 = (bs[1] - z1) & 1; y1 < 7; y1 += 2)
              for (int y2 = (bs[2] - z2) & 1; y2 < 7; y2 += 2)
              {
                f0[x0][x1][x2][s >> 1][(y0 + z0) >> 1][(y1 + z1) >> 1][(y2 + z2) >> 1] += f3[x0][x1][x2][x3][y0][y1][y2];
              }
            }
          }
        }
      }
      ans += f0[0][0][0][0][0][0][0];
    }
    printf("%u\n", ans.x);
  }
  return 0;
}
0