結果

問題 No.1689 Set Cards
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-09-24 22:21:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,793 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 205,888 KB
実行使用メモリ 814,708 KB
最終ジャッジ日時 2023-09-18 21:40:02
合計ジャッジ時間 12,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 197 ms
23,748 KB
testcase_01 AC 248 ms
27,836 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 85 ms
15,564 KB
testcase_09 AC 85 ms
15,464 KB
testcase_10 WA -
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

#define mint modint<mod2>
template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream& os, const modint& m) {
    return os << m.value();
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> pw3(13);
  pw3[0] = 1;
  rep(i, 13) if(i) pw3[i] = pw3[i-1]*3;
  vector<int> B(n);
  rep(i, n) {
    int k; cin >> k;
    rep(j, k) {
      int c; cin >> c;
      c--;
      B[i] += pw3[c];
    }
  }
  vector<vector<mint>> dp(n+1, vector<mint>(pw3[12]));
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, pw3[12]) {
      dp[i+1][j] += dp[i][j];
      int nx = 0;
      rep(k, 12) {
        int b = min(2, (j/pw3[k]%3) + (B[i]/pw3[k]%3));
        nx += b * pw3[k];
      }
      dp[i+1][nx] += dp[i][j];
    }
  }
  mint ans = 0;
  rep(j, pw3[12]) {
    bool ok = true;
    rep(k, 12) if(j/pw3[k]%3 == 1) ok = false;
    if(ok) ans += dp[n][j];
  }
  cout << ans-1 << endk;
  return 0;
}
0