結果

問題 No.2136 Dice Calendar?
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-10 21:24:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,858 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 164,192 KB
最終ジャッジ日時 2023-09-07 00:45:06
合計ジャッジ時間 17,433 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,700 KB
testcase_01 AC 17 ms
8,216 KB
testcase_02 AC 225 ms
13,528 KB
testcase_03 AC 17 ms
8,008 KB
testcase_04 AC 16 ms
8,248 KB
testcase_05 AC 28 ms
8,572 KB
testcase_06 AC 26 ms
8,448 KB
testcase_07 AC 42 ms
8,876 KB
testcase_08 AC 72 ms
9,824 KB
testcase_09 AC 163 ms
12,440 KB
testcase_10 AC 242 ms
14,072 KB
testcase_11 AC 696 ms
26,080 KB
testcase_12 AC 945 ms
30,568 KB
testcase_13 AC 732 ms
24,856 KB
testcase_14 AC 1,317 ms
39,688 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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): # diceSet[0]で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 - ((1 << result * 5 + 5) - 1))
			nextQueue.append((nextSet, nextPartition))

# (多重集合を、仕切りの考え方で見なした時のbit列, 上のbit列で立っているbitの位置)の二要素を状態とする
nowQueue = [(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[0] >> 6] = 0
	nextQueue = []
	for diceSet in nowQueue: nextSet(diceSet, dice, uniqueCheck, nextQueue)
	nowQueue = nextQueue

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