結果

問題 No.2136 Dice Calendar?
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-09 19:13:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,980 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 27,600 KB
最終ジャッジ日時 2023-09-05 22:34:12
合計ジャッジ時間 9,124 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,224 KB
testcase_01 AC 16 ms
8,280 KB
testcase_02 AC 610 ms
14,892 KB
testcase_03 AC 17 ms
8,264 KB
testcase_04 AC 18 ms
8,160 KB
testcase_05 AC 32 ms
8,624 KB
testcase_06 AC 29 ms
8,552 KB
testcase_07 AC 49 ms
8,892 KB
testcase_08 AC 126 ms
10,200 KB
testcase_09 AC 425 ms
13,180 KB
testcase_10 AC 945 ms
15,100 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
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))

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 & 1) == 0: # まだこの多重集合を計算対象にしていないなら
				uniqueCheck |= 1 << nextSet
				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要素の集合として管理される
for dice in S:
	uniqueCheck = 0 # 既に調べた多重集合を管理するためのBitSet
	nextQueue = []
	for diceSet in nowQueue: uniqueCheck = diceSet.next(dice, uniqueCheck, nextQueue)
	nowQueue = nextQueue

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