結果

問題 No.3004 ヤング図形
ユーザー rlangevin
提出日時 2025-01-21 12:20:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,130 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 82,628 KB
実行使用メモリ 129,744 KB
最終ジャッジ日時 2025-01-21 12:21:51
合計ジャッジ時間 97,671 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353



K = int(input())
L, M = [0] * K, [0] * K
S = 0
for i in range(K):
    L[i], M[i] = map(int, input().split())
    S += L[i] * M[i]
    
ans = 1
SS = set()
for i in range(K):
    # ans *= comb(S, L[i] * M[i])
    SS.add(S)
    SS.add(L[i] * M[i])
    SS.add(S - L[i] * M[i])
    SS.add(L[i])
    SS.add(M[i])
    S -= L[i] * M[i]   
    
from collections import *
fact = defaultdict(lambda x : 1)
invfact = defaultdict(lambda x : 1)
pre = 1
n = 10 ** 8 + 5
for i in range(1, n):
    pre = ((i+1) * pre) % mod
    if i + 1 in SS:
        fact[i + 1] = pre
        
pre = pow(pre, mod - 2, mod)
for i in range(n - 1, -1, -1):
    pre = pre * (i + 1) % mod
    if i in SS:
        invfact[i] = pre


def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod
    
for i in range(K):
    S += L[i] * M[i]
    
for i in range(K):
    ans *= comb(S, L[i] * M[i])
    ans %= mod
    S -= L[i] * M[i]
    ans *= fact[L[i] * M[i]]
    ans %= mod
    ans *= pow(invfact[L[i]], M[i], mod)
    ans %= mod
    ans *= invfact[M[i]]
    ans %= mod
    
print(ans)
0