結果

問題 No.2136 Dice Calendar?
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-14 12:40:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,159 ms / 5,000 ms
コード長 1,882 bytes
コンパイル時間 1,392 ms
コンパイル使用メモリ 86,492 KB
実行使用メモリ 505,772 KB
最終ジャッジ日時 2023-09-08 19:39:31
合計ジャッジ時間 26,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,356 KB
testcase_01 AC 70 ms
71,200 KB
testcase_02 AC 113 ms
79,292 KB
testcase_03 AC 75 ms
71,140 KB
testcase_04 AC 72 ms
71,376 KB
testcase_05 AC 95 ms
77,156 KB
testcase_06 AC 91 ms
76,920 KB
testcase_07 AC 102 ms
78,100 KB
testcase_08 AC 107 ms
77,516 KB
testcase_09 AC 114 ms
78,396 KB
testcase_10 AC 117 ms
79,064 KB
testcase_11 AC 143 ms
85,436 KB
testcase_12 AC 167 ms
88,188 KB
testcase_13 AC 148 ms
84,896 KB
testcase_14 AC 193 ms
93,032 KB
testcase_15 AC 522 ms
160,328 KB
testcase_16 AC 704 ms
193,956 KB
testcase_17 AC 570 ms
166,248 KB
testcase_18 AC 1,638 ms
313,768 KB
testcase_19 AC 2,263 ms
354,664 KB
testcase_20 AC 1,789 ms
327,868 KB
testcase_21 AC 3,672 ms
468,916 KB
testcase_22 AC 4,159 ms
505,772 KB
testcase_23 AC 3,711 ms
494,228 KB
testcase_24 AC 125 ms
136,768 KB
testcase_25 AC 183 ms
151,960 KB
testcase_26 AC 3,147 ms
466,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))

def getPartition(diceSet, index): # 多重集合を表すbitでi番目に立っているbitの位置を求める
	return diceSet[1] >> 5 * index & 0b11111

def multichoose(diceSet): # この多重集合を並べてできる組合せ
	ret = factorial[getPartition(diceSet, 9) - 9]
	for i in range(9): ret //= factorial[getPartition(diceSet, i + 1) - getPartition(diceSet, i) - 1]
	return ret

def nextSet(diceSet, dice, uniqueCheck, nextQueue): # diceを追加したときの多重集合をnextQueueに入れる
	for result in dice: # 出目がresultだった時
		mask = (1 << getPartition(diceSet, result)) - 1
		nextSet = (diceSet[0] & 0x1FFFFFFF - mask) << 1 | diceSet[0] & mask
		if (uniqueCheck[nextSet >> 6] >> (nextSet & 0x3F) & 1) == 0: # まだこの多重集合を計算対象にしていないなら
			uniqueCheck[nextSet >> 6] |= 1 << (nextSet & 0x3F)
			nextPartition = diceSet[1] + (0b00001_00001_00001_00001_00001_00001_00001_00001_00001_00001 & 0x3FFFFFFFFFFFF - ((0x20 << result * 5) - 1))
			nextQueue.append((nextSet, nextPartition))

# (多重集合を、仕切りの考え方で見なした時のbit列, 上のbit列で立っているbitの位置)の二要素を状態とする
nowQueue = [(0b111111111, 0b01001_01000_00111_00110_00101_00100_00011_00010_00001_00000)] # 初項M_0を求める
uniqueCheck = [0] * (1 << N + 3) # 既に調べた多重集合を管理するためのBitSet、64MB程度
for dice in S:
	for i in nowQueue: uniqueCheck[i[0] >> 6] = 0
	nextQueue = []
	for diceSet in nowQueue: nextSet(diceSet, dice, uniqueCheck, nextQueue) # M_iからM_{i+1}を求める
	nowQueue = nextQueue

ans = 0
for diceSet in nowQueue: ans += multichoose(diceSet)
ans %= 998_244_353
print(ans)
0