結果
問題 |
No.1186 長方形の敷き詰め
|
ユーザー |
|
提出日時 | 2023-11-16 12:06:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 378 ms / 2,000 ms |
コード長 | 1,112 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 249,984 KB |
最終ジャッジ日時 | 2024-09-26 05:06:15 |
合計ジャッジ時間 | 4,881 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) mod = 998244353 class combination(): def __init__(self,N,p): self.fact = [1, 1] # fact[n] = (n! mod p) self.factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) self.inv = [0, 1] # factinv 計算用 self.p = p for i in range(2, N + 1): self.fact.append((self.fact[-1] * i) % p) self.inv.append((-self.inv[p % i] * (p // i)) % p) self.factinv.append((self.factinv[-1] * self.inv[-1]) % p) def cmb(self,n, r): if (r < 0) or (n < r): return 0 r = min(r, n - r) return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.p C = combination(M+1,mod) if N>M: print(1) exit() if N==1: print(1) exit() ans = 1 cnt = 1 while M - N*cnt >=0 : ans += C.cmb(M-cnt*(N-1),cnt) # print(cnt,C.cmb(M-cnt*(N-1),cnt)) ans %= mod cnt += 1 print(ans)