結果
| 問題 |
No.2136 Dice Calendar?
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:38:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,273 bytes |
| コンパイル時間 | 378 ms |
| コンパイル使用メモリ | 81,940 KB |
| 実行使用メモリ | 381,856 KB |
| 最終ジャッジ日時 | 2025-06-12 18:39:19 |
| 合計ジャッジ時間 | 24,073 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 TLE * 2 -- * 8 |
ソースコード
MOD = 998244353
def main():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx])
idx += 1
dice = []
for _ in range(N):
digits = list(map(int, input[idx:idx+6]))
idx +=6
dice.append(digits)
# Precompute factorial and inverse factorial modulo MOD
max_n = N
fact = [1] * (max_n + 1)
for i in range(1, max_n + 1):
fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (max_n + 1)
inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)
for i in range(max_n-1, -1, -1):
inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
current_states = set()
initial = tuple([0]*9)
current_states.add(initial)
for die in dice:
new_states = set()
for state in current_states:
for d in die:
cnt = list(state)
idx_d = d - 1
cnt[idx_d] += 1
new_state = tuple(cnt)
new_states.add(new_state)
current_states = new_states
total = 0
for state in current_states:
res = fact[N]
for c in state:
res = res * inv_fact[c] % MOD
total = (total + res) % MOD
print(total)
if __name__ == '__main__':
main()
gew1fw