結果

問題 No.2136 Dice Calendar?
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-14 12:15:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,004 ms / 5,000 ms
コード長 2,303 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 83,200 KB
実行使用メモリ 230,900 KB
最終ジャッジ日時 2023-09-08 19:38:06
合計ジャッジ時間 8,087 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
68,868 KB
testcase_01 AC 19 ms
68,804 KB
testcase_02 AC 24 ms
69,520 KB
testcase_03 AC 19 ms
68,940 KB
testcase_04 AC 19 ms
68,948 KB
testcase_05 AC 19 ms
68,884 KB
testcase_06 AC 19 ms
69,032 KB
testcase_07 AC 20 ms
69,072 KB
testcase_08 AC 20 ms
69,168 KB
testcase_09 AC 23 ms
69,484 KB
testcase_10 AC 24 ms
69,656 KB
testcase_11 AC 35 ms
72,476 KB
testcase_12 AC 41 ms
72,404 KB
testcase_13 AC 36 ms
72,400 KB
testcase_14 AC 51 ms
77,588 KB
testcase_15 AC 125 ms
88,912 KB
testcase_16 AC 164 ms
100,004 KB
testcase_17 AC 124 ms
87,628 KB
testcase_18 AC 349 ms
132,028 KB
testcase_19 AC 429 ms
133,728 KB
testcase_20 AC 510 ms
147,776 KB
testcase_21 AC 669 ms
160,944 KB
testcase_22 AC 776 ms
213,264 KB
testcase_23 AC 1,004 ms
230,900 KB
testcase_24 AC 19 ms
68,948 KB
testcase_25 AC 39 ms
71,124 KB
testcase_26 AC 884 ms
194,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
using ll = long long int;
typedef bitset<1 << 29> bs; // 64MB程度

class dice_set {
  private:
    int multiset; // 多重集合を、仕切りの考え方で見なした時のbit列
    ll partition; // multisetで立っているbitの位置、5bitごとに管理
    int get_partition(int index) { // multisetでindex番目に立っているbitの位置を求める
      return partition >> 5 * index & 0b11111;
    }
  public:
    dice_set() : dice_set(0b111111111, 0b01001'01000'00111'00110'00101'00100'00011'00010'00001'00000ll) {}
    dice_set(int multiset_, ll partition_) : multiset(multiset_), partition(partition_) {}
    
    ll multichoose(ll *factorial) { // この多重集合を並べてできる組合せ
      ll ans = factorial[get_partition(9) - 9];
      for (int i = 0;i < 9;++ i) ans /= factorial[get_partition(i + 1) - get_partition(i) - 1];
      return ans;
    }
    
    void next(vector<int> &dice, bs &check_unique, vector<dice_set> &que) { // diceを追加したときにできる新たな多重集合のうち、新しく発見したものをqueに入れる
      for (int result : dice) {
        int mask = (1 << get_partition(result)) - 1;
        int nextset = (multiset & ~mask) << 1 | (multiset & mask);
        if (check_unique[nextset]) continue;
        check_unique.set(nextset);
        ll next_partition = partition + (0b00001'00001'00001'00001'00001'00001'00001'00001'00001'00001ll & ~((0x20ll << result * 5) - 1));
        que.push_back(dice_set(nextset, next_partition));
      }
    }
};

int main() {
  int N;
  cin >> N;
  vector<vector<int>> S(N, vector<int>(6));
  for (int i = 0;i < N;++ i) for (int j = 0;j < 6;++ j) {
    cin >> S[i][j];
    -- S[i][j];
  }
  
  ll factorial[21] = {1};
  for (int i = 1;i <= 20;++ i) factorial[i] = factorial[i - 1] * i;
  
  vector<dice_set> now_queue(1, dice_set()); // 初項M_0を求める
  bs uniquecheck(0);
  for (vector<int> dice : S) {
    vector<dice_set> next_queue;
    for (auto d : now_queue) d.next(dice, uniquecheck, next_queue); // M_iからM_{i+1}を求める
    now_queue = next_queue;
  }
  int ans = 0;
  for (auto d : now_queue) ans = (int)((ans + d.multichoose(factorial)) % 998'244'353);
  cout << ans << endl;
}
0