結果

問題 No.3004 ヤング図形
ユーザー rlangevin
提出日時 2025-01-21 12:26:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,523 ms / 4,000 ms
コード長 1,202 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 81,992 KB
実行使用メモリ 71,348 KB
最終ジャッジ日時 2025-01-21 12:27:20
合計ジャッジ時間 45,115 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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
SS = sorted(list(SS)) + [n]
now = 0
for i in range(n):
    if i == SS[now]:
        fact[i] = pre
        now += 1
    pre = ((i+1) * pre) % mod
        
pre = pow(pre, mod - 2, mod)
for i in range(n - 1, -1, -1):
    pre = pre * (i + 1) % mod
    if i == SS[now - 1]:
        invfact[i] = pre
        now -= 1

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