結果

問題 No.2572 Midori on the grid
ユーザー aplysiaSheepaplysiaSheep
提出日時 2023-11-13 15:58:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 522 ms / 5,000 ms
コード長 823 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 119,524 KB
最終ジャッジ日時 2023-11-13 16:51:45
合計ジャッジ時間 5,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 522 ms
119,524 KB
testcase_01 AC 309 ms
112,412 KB
testcase_02 AC 427 ms
103,084 KB
testcase_03 AC 387 ms
103,368 KB
testcase_04 AC 235 ms
87,656 KB
testcase_05 AC 422 ms
104,820 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 34 ms
53,460 KB
testcase_08 AC 34 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline

MOD = 998244353

COMB_MAX_SIZE = 1  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用


def comb(n, r, p=MOD):
    if r < 0 or n < r:
        return 0

    global COMB_MAX_SIZE

    if COMB_MAX_SIZE < n:
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            factinv.append((factinv[-1] * inv[-1]) % MOD)

        COMB_MAX_SIZE = n

    return fact[n] * factinv[r] * factinv[n - r] % p


h, w, q = map(int, input().split())

for i in range(q):
    t = int(input())
    if t * (h - w + t) < 0:
        print(0)
    else:
        print((comb(h + w, h) - comb(h + w, h + t)) % MOD)
0