結果

問題 No.1186 長方形の敷き詰め
ユーザー yakeshibayakeshiba
提出日時 2020-11-18 10:26:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,463 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 153,296 KB
最終ジャッジ日時 2023-09-30 14:52:51
合計ジャッジ時間 7,652 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 74 ms
71,260 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 AC 74 ms
71,592 KB
testcase_07 WA -
testcase_08 AC 73 ms
71,400 KB
testcase_09 TLE -
testcase_10 RE -
testcase_11 AC 74 ms
71,464 KB
testcase_12 AC 74 ms
71,560 KB
testcase_13 AC 74 ms
71,264 KB
testcase_14 AC 73 ms
71,276 KB
testcase_15 AC 75 ms
71,272 KB
testcase_16 RE -
testcase_17 AC 74 ms
71,268 KB
testcase_18 AC 74 ms
71,492 KB
testcase_19 AC 75 ms
71,396 KB
testcase_20 AC 75 ms
71,560 KB
testcase_21 AC 75 ms
71,584 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 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(ans%mod)
0