結果

問題 No.1520 Zigzag Sum
ユーザー AEnAEn
提出日時 2022-11-23 14:55:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,006 ms / 2,000 ms
コード長 372 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 81,504 KB
実行使用メモリ 92,472 KB
最終ジャッジ日時 2023-10-25 00:08:48
合計ジャッジ時間 11,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 721 ms
75,168 KB
testcase_01 AC 720 ms
75,168 KB
testcase_02 AC 968 ms
91,564 KB
testcase_03 AC 1,004 ms
92,472 KB
testcase_04 AC 1,003 ms
92,472 KB
testcase_05 AC 1,006 ms
92,472 KB
testcase_06 AC 983 ms
92,472 KB
testcase_07 AC 976 ms
91,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 10**6
fac = [0]*N
inv = [0]*N
fac[0] = inv[0] = 1
mod = 10**9+7

for i in range(1,N):
    fac[i] = (fac[i-1]*i)%mod
    inv[i] = (inv[i-1]*pow(i,mod-2,mod))%mod

T = int(input())
for i in range(T):
    H, W = map(int, input().split())
    if H==1 or W==1:
        print(0)
    else:
        ncr = (fac[H-2+W-2]*inv[H-2]*inv[W-2])%mod
        print((2*(H+W-3)*ncr)%mod)
0