結果

問題 No.1520 Zigzag Sum
ユーザー mkawa2mkawa2
提出日時 2021-05-28 21:44:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 918 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 11,148 KB
実行使用メモリ 40,140 KB
最終ジャッジ日時 2023-08-07 05:45:31
合計ジャッジ時間 7,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
39,940 KB
testcase_01 AC 277 ms
39,764 KB
testcase_02 AC 863 ms
40,140 KB
testcase_03 AC 911 ms
39,844 KB
testcase_04 AC 918 ms
39,820 KB
testcase_05 AC 914 ms
39,952 KB
testcase_06 AC 866 ms
39,896 KB
testcase_07 AC 866 ms
39,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

def nHr(hn, hr):
    return nCr(hn+hr-1, hr-1)

def nPr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_n-com_r]%md

def nCr(com_n, com_r):
    if com_r < 0: return 0
    if com_n < com_r: return 0
    return fac[com_n]*ifac[com_r]%md*ifac[com_n-com_r]%md

# 準備
n_max = 400005
fac = [1]
for i in range(1, n_max+1): fac.append(fac[-1]*i%md)
ifac = [1]*(n_max+1)
ifac[n_max] = pow(fac[n_max], md-2, md)
for i in range(n_max-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%md

for _ in range(II()):
    h, w = LI()
    h, w = h-1, w-1
    n = h+w
    ans = w*pow(n, md-2, md)*2*h*nCr(n, h)%md
    print(ans)
0