結果

問題 No.2159 Filling 4x4 array
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-12-11 02:32:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 6,571 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 167,660 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 02:13:53
合計ジャッジ時間 4,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 27 ms
5,248 KB
testcase_03 AC 27 ms
5,248 KB
testcase_04 AC 26 ms
5,248 KB
testcase_05 AC 27 ms
5,248 KB
testcase_06 AC 28 ms
5,248 KB
testcase_07 AC 29 ms
5,248 KB
testcase_08 AC 27 ms
5,248 KB
testcase_09 AC 26 ms
5,248 KB
testcase_10 AC 27 ms
5,248 KB
testcase_11 AC 28 ms
5,248 KB
testcase_12 AC 28 ms
5,248 KB
testcase_13 AC 28 ms
5,248 KB
testcase_14 AC 26 ms
5,248 KB
testcase_15 AC 27 ms
5,248 KB
testcase_16 AC 27 ms
5,248 KB
testcase_17 AC 27 ms
5,248 KB
testcase_18 AC 27 ms
5,248 KB
testcase_19 AC 28 ms
5,248 KB
testcase_20 AC 27 ms
5,248 KB
testcase_21 AC 28 ms
5,248 KB
testcase_22 AC 27 ms
5,248 KB
testcase_23 AC 26 ms
5,248 KB
testcase_24 AC 27 ms
5,248 KB
testcase_25 AC 26 ms
5,248 KB
testcase_26 AC 27 ms
5,248 KB
testcase_27 AC 26 ms
5,248 KB
testcase_28 AC 26 ms
5,248 KB
testcase_29 AC 28 ms
5,248 KB
testcase_30 AC 28 ms
5,248 KB
testcase_31 AC 26 ms
5,248 KB
testcase_32 AC 27 ms
5,248 KB
testcase_33 AC 27 ms
5,248 KB
testcase_34 AC 28 ms
5,248 KB
testcase_35 AC 29 ms
5,248 KB
testcase_36 AC 27 ms
5,248 KB
testcase_37 AC 27 ms
5,248 KB
testcase_38 AC 27 ms
5,248 KB
testcase_39 AC 27 ms
5,248 KB
testcase_40 AC 27 ms
5,248 KB
testcase_41 AC 27 ms
5,248 KB
testcase_42 AC 27 ms
5,248 KB
testcase_43 AC 26 ms
5,248 KB
testcase_44 AC 27 ms
5,248 KB
testcase_45 AC 2 ms
5,248 KB
testcase_46 AC 2 ms
5,248 KB
testcase_47 AC 2 ms
5,248 KB
testcase_48 AC 2 ms
5,248 KB
testcase_49 AC 2 ms
5,248 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> 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