結果

問題 No.1186 長方形の敷き詰め
ユーザー yakeshibayakeshiba
提出日時 2020-11-18 10:36:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,052 ms / 2,000 ms
コード長 2,521 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 153,528 KB
最終ジャッジ日時 2023-09-30 14:53:19
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,336 KB
testcase_01 AC 73 ms
71,272 KB
testcase_02 AC 71 ms
71,272 KB
testcase_03 AC 72 ms
71,432 KB
testcase_04 AC 75 ms
71,620 KB
testcase_05 AC 73 ms
71,320 KB
testcase_06 AC 72 ms
71,084 KB
testcase_07 AC 73 ms
71,436 KB
testcase_08 AC 71 ms
71,564 KB
testcase_09 AC 72 ms
71,572 KB
testcase_10 AC 71 ms
71,628 KB
testcase_11 AC 71 ms
71,116 KB
testcase_12 AC 72 ms
71,444 KB
testcase_13 AC 72 ms
71,436 KB
testcase_14 AC 71 ms
71,492 KB
testcase_15 AC 72 ms
71,316 KB
testcase_16 AC 71 ms
71,440 KB
testcase_17 AC 72 ms
71,492 KB
testcase_18 AC 72 ms
71,080 KB
testcase_19 AC 70 ms
71,328 KB
testcase_20 AC 71 ms
71,276 KB
testcase_21 AC 72 ms
71,436 KB
testcase_22 AC 1,052 ms
153,528 KB
testcase_23 AC 118 ms
118,464 KB
testcase_24 AC 100 ms
101,504 KB
testcase_25 AC 81 ms
80,408 KB
testcase_26 AC 73 ms
71,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
class Mint:
    MOD = 998244353  # Must be a prime
    CACHE_FACTORIALS = [1, 1]
 
    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v
        else:
            self.v = v % self.MOD
 
    @property
    def inv(self):
        return Mint(self.__minv(self.v))
 
    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])
 
    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)
 
    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)
 
    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)
 
    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)
 
    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)
 
    def __str__(self):
        return str(self.v)
    __repr__ = __str__
 
    def __int__(self):
        return self.v
 
    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w
 
    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__
 
    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)
 
    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)
 
    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__
 
    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else Mint(self.v * self.__minv(w))
 
    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else Mint(u * self.__minv(self.v))
 
    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else Mint(self.__mpow(self.v, w))
 
    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else Mint(self.__mpow(u, self.v))
 

n, m = map(int,input().split())

if n == 1:
    print(1)
    exit()

if m < n:
    print(1)
    exit()

ans = 1
for i in range(1,m//n+1):
    rest = m-n*i
    ans += Mint.comb(i+rest, i)
    
print(int(ans)%mod)
0