結果

問題 No.1520 Zigzag Sum
ユーザー rlangevinrlangevin
提出日時 2023-04-22 17:32:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-24 20:40:50
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
64,640 KB
testcase_01 AC 54 ms
65,152 KB
testcase_02 AC 106 ms
82,944 KB
testcase_03 AC 131 ms
83,072 KB
testcase_04 AC 126 ms
82,816 KB
testcase_05 AC 128 ms
82,432 KB
testcase_06 AC 125 ms
82,304 KB
testcase_07 AC 117 ms
82,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

n = 404040
mod = 10 ** 9 + 7

fact = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
inv[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * inv[r] * inv[n - r] % mod

T = int(readline())
for _ in range(T):
    H, W = map(int, readline().split())
    print(2 * (H + W - 3) * comb(H + W - 4 , H - 2) % mod)
0