結果

問題 No.1186 長方形の敷き詰め
ユーザー FromBooskaFromBooska
提出日時 2023-02-20 18:09:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 919 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 80,668 KB
最終ジャッジ日時 2023-09-28 15:06:27
合計ジャッジ時間 7,245 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,464 KB
testcase_01 AC 76 ms
71,192 KB
testcase_02 AC 76 ms
71,084 KB
testcase_03 AC 74 ms
71,240 KB
testcase_04 AC 77 ms
71,076 KB
testcase_05 AC 77 ms
71,212 KB
testcase_06 AC 77 ms
71,268 KB
testcase_07 AC 77 ms
71,224 KB
testcase_08 AC 74 ms
71,132 KB
testcase_09 AC 75 ms
71,236 KB
testcase_10 AC 75 ms
71,296 KB
testcase_11 AC 76 ms
71,000 KB
testcase_12 AC 78 ms
71,244 KB
testcase_13 AC 77 ms
71,208 KB
testcase_14 AC 75 ms
71,280 KB
testcase_15 AC 76 ms
71,048 KB
testcase_16 AC 74 ms
71,268 KB
testcase_17 AC 76 ms
71,284 KB
testcase_18 AC 77 ms
71,292 KB
testcase_19 AC 75 ms
71,220 KB
testcase_20 AC 79 ms
71,084 KB
testcase_21 AC 78 ms
70,968 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# N=1なら方法は1つだけ
# M<Nでも方法は1つだけ
# M>=Nなら、全部縦が1通り、横に何回置くかでnCr

# nCr 高速化
# powの2項目をMOD-2にしてpypyで動くように改造
def nCr(N, R, MOD):
    numerator = 1
    for n in range(N-R+1, N+1):
        numerator *= n
        numerator %= MOD
        #ここをnumerator *= n%MODだとアウト、ちゃんとmodされていかないので低速
    denom = 1
    for r in range(1, R+1):
        denom *= r
        denom %= MOD
    denom_inverse = pow(denom, MOD-2, MOD)
    return numerator * denom_inverse %MOD

N, M = map(int, input().split())
mod = 998244353
if N == 1:
    ans = 1
elif M < N:
    ans = 1
else:
    howmany = M//N
    #print('howmany', howmany)
    ans = 1
    for k in range(1, howmany+1):
        n = k + M - N*k
        ans += nCr(n, k, mod)
        ans %= mod
        #print(k, n, nCr(n, k, mod))
print(ans)   
0