結果
問題 | No.2136 Dice Calendar? |
ユーザー | CuriousFairy315 |
提出日時 | 2022-10-10 21:11:59 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,039 bytes |
コンパイル時間 | 481 ms |
コンパイル使用メモリ | 87,248 KB |
実行使用メモリ | 795,364 KB |
最終ジャッジ日時 | 2023-09-07 00:12:13 |
合計ジャッジ時間 | 27,668 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,584 KB |
testcase_01 | AC | 70 ms
71,620 KB |
testcase_02 | AC | 121 ms
82,020 KB |
testcase_03 | AC | 70 ms
71,364 KB |
testcase_04 | AC | 71 ms
71,484 KB |
testcase_05 | AC | 101 ms
78,100 KB |
testcase_06 | AC | 96 ms
77,052 KB |
testcase_07 | AC | 101 ms
77,908 KB |
testcase_08 | AC | 111 ms
78,316 KB |
testcase_09 | AC | 115 ms
80,504 KB |
testcase_10 | AC | 136 ms
82,912 KB |
testcase_11 | AC | 177 ms
94,840 KB |
testcase_12 | AC | 207 ms
100,560 KB |
testcase_13 | AC | 181 ms
94,976 KB |
testcase_14 | AC | 241 ms
108,088 KB |
testcase_15 | AC | 759 ms
236,988 KB |
testcase_16 | AC | 1,075 ms
280,968 KB |
testcase_17 | AC | 881 ms
234,376 KB |
testcase_18 | AC | 2,486 ms
414,556 KB |
testcase_19 | AC | 3,234 ms
458,508 KB |
testcase_20 | MLE | - |
testcase_21 | TLE | - |
testcase_22 | MLE | - |
testcase_23 | TLE | - |
testcase_24 | AC | 153 ms
104,268 KB |
testcase_25 | AC | 220 ms
133,100 KB |
testcase_26 | MLE | - |
ソースコード
N = int(input()) S = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)] factorial = [1] for i in range(N): factorial.append(factorial[i] * (i + 1)) class DiceSet: # ダイスから作られる整数の多重集合を管理 def __init__(self, multiset, partition): self.multiset = multiset # 多重集合を、仕切りの考え方で見なした時のbit列 self.partition = partition # multisetで立っているbitの位置 def getPartition(self, index): # multisetでi番目に立っているbitの位置を求める return self.partition >> 5 * index & 0b11111 def multichoose(self): # この多重集合を並べてできる組合せ ret = factorial[self.getPartition(9) - 9] for i in range(9): ret //= factorial[self.getPartition(i + 1) - self.getPartition(i) - 1] return ret def next(self, dice, uniqueCheck, nextQueue): # diceを追加したときの多重集合をnextQueueに入れる for result in dice: # 出目がresultだった時 mask = (1 << self.getPartition(result)) - 1 nextSet = (self.multiset & 0x1FFFFFFF - mask) << 1 | self.multiset & mask if (uniqueCheck[nextSet >> 6] >> (nextSet & 0x3F) & 1) == 0: # まだこの多重集合を計算対象にしていないなら uniqueCheck[nextSet >> 6] |= 1 << (nextSet & 0x3F) nextPartition = self.partition + (0b00001_00001_00001_00001_00001_00001_00001_00001_00001_00001 & 0x3FFFFFFFFFFFF - ((1 << result * 5 + 5) - 1)) nextQueue.append(DiceSet(nextSet, nextPartition)) return uniqueCheck nowQueue = [DiceSet(0b11111111, 0b01001_01000_00111_00110_00101_00100_00011_00010_00001_00000)] # 初期値は、0要素の集合として管理される uniqueCheck = [0] * (1 << N + 2) # 既に調べた多重集合を管理するためのBitSet for dice in S: for i in nowQueue: uniqueCheck[i.multiset >> 6] = 0 nextQueue = [] for diceSet in nowQueue: diceSet.next(dice, uniqueCheck, nextQueue) nowQueue = nextQueue ans = 0 for diceSet in nowQueue: ans += diceSet.multichoose() ans %= 998_244_353 print(ans)