結果
問題 | No.2136 Dice Calendar? |
ユーザー |
![]() |
提出日時 | 2022-10-14 12:15:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,049 ms / 5,000 ms |
コード長 | 2,303 bytes |
コンパイル時間 | 1,014 ms |
コンパイル使用メモリ | 81,632 KB |
最終ジャッジ日時 | 2025-02-08 03:17:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#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; }