結果
| 問題 |
No.2136 Dice Calendar?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-21 15:33:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,969 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,376 KB |
| 実行使用メモリ | 67,372 KB |
| 最終ジャッジ日時 | 2024-07-01 01:08:49 |
| 合計ジャッジ時間 | 2,849 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 24 |
ソースコード
import numpy as np
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))
partition = [0] * 10
partition[9] = N + 9
deBrujin32 = [0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9]
def numberOfTrailingZeros(i): return deBrujin32[i * 0x077CB531 >> 27 & 0b11111] # 丁度1bit立っている値に対してその立っている位置を返す
def calcPartition(multiSet): # 与えられた多重集合に対して、立っているbitの位置を保持する数列Pを返す
for i in range(1, 9):
lob = multiSet & -multiSet
partition[i] = numberOfTrailingZeros(lob) + 1
multiSet -= lob
def multichoose(multiSet): # multiSetで与えられた多重集合を並べてできる組合せ
calcPartition(multiSet)
ret = factorial[N]
for i in range(9): ret //= factorial[partition[i + 1] - partition[i] - 1]
return ret
def nextSet(multiSet, dice, uniqueCheck, nextList): # diceを追加したときの多重集合をnextListに入れる
calcPartition(multiSet)
for result in dice: # 出目がresultだった時
mask = (1 << partition[result]) - 1
nextSet = (multiSet & 0x1FFFFFFF - mask) << 1 | (multiSet & mask)
if (uniqueCheck[nextSet >> 6] & 1 << (nextSet & 0x3F)) == 0: # まだこの多重集合を計算対象にしていないなら
uniqueCheck[nextSet >> 6] |= 1 << (nextSet & 0x3F)
nextList.append(nextSet)
nowList = [0b11111111] # 初項M_0を求める
uniqueCheck = np.zeros((N+2,),dtype=np.int) # 既に調べた多重集合を管理するためのBitSet、32MB程度
for dice in S:
for i in nowList: uniqueCheck[i >> 6] = 0
nextList = []
for multiSet in nowList: nextSet(multiSet, dice, uniqueCheck, nextList) # M_iからM_{i+1}を求める
nowList = nextList
ans = 0
for multiSet in nowList: ans += multichoose(multiSet)
ans %= 998_244_353
print(ans)