結果

問題 No.1520 Zigzag Sum
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-03-31 18:29:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 88,764 KB
最終ジャッジ日時 2023-10-26 03:39:20
合計ジャッジ時間 3,312 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
71,900 KB
testcase_01 AC 60 ms
71,900 KB
testcase_02 AC 301 ms
88,748 KB
testcase_03 AC 337 ms
88,764 KB
testcase_04 AC 332 ms
88,764 KB
testcase_05 AC 333 ms
88,764 KB
testcase_06 AC 309 ms
88,764 KB
testcase_07 AC 307 ms
88,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7

class combinations:
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n * 2 + 1)
        self.fi = [1] * (self.n * 2 + 1)

        for i in range(1, self.n * 2 + 1):
            self.fa[i] = self.fa[i - 1] * i % mod

        self.fi[-1] = pow(self.fa[-1], mod - 2, mod)

        for i in range(self.n * 2, 0, -1):
            self.fi[i - 1] = self.fi[i] * i % mod

    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod

    def perm(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[n - r] % mod
        
    def combr(self, n, r):
        if n == r == 0:return 1
        return self.comb(n + r - 1, r)

#拡張Euclidの互除法
def extgcd(a, b, d = 0):
    g = a
    if b == 0:
        x, y = 1, 0
    else:
        x, y, g = extgcd(b, a % b)
        x, y = y, x - a // b * y
    return x, y, g

#mod p における逆元
def invmod(a, p):
    x, y, g = extgcd(a, p)
    x %= p
    return x

t = int(input())
COMB = combinations(4 * 10 ** 5)
for _ in range(t):
    h, w = map(int, input().split())
    if h == 1 or w == 1: print(0); continue
    print(2 * (h + w - 3) * COMB.comb(h + w - 4, h - 2) % mod)
0