結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー hirakuhiraku
提出日時 2021-07-10 15:53:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 104,948 KB
最終ジャッジ日時 2023-09-14 19:34:28
合計ジャッジ時間 6,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 86 ms
82,008 KB
testcase_02 AC 374 ms
104,840 KB
testcase_03 AC 379 ms
104,896 KB
testcase_04 AC 374 ms
104,760 KB
testcase_05 AC 362 ms
104,740 KB
testcase_06 AC 362 ms
104,784 KB
testcase_07 AC 363 ms
104,768 KB
testcase_08 AC 368 ms
104,748 KB
testcase_09 AC 356 ms
104,680 KB
testcase_10 AC 358 ms
104,700 KB
testcase_11 AC 331 ms
104,852 KB
testcase_12 AC 328 ms
104,696 KB
testcase_13 AC 327 ms
104,948 KB
testcase_14 AC 76 ms
71,268 KB
testcase_15 AC 73 ms
71,312 KB
testcase_16 AC 73 ms
71,116 KB
testcase_17 AC 72 ms
71,120 KB
testcase_18 AC 72 ms
71,232 KB
testcase_19 AC 75 ms
71,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
TXY = [list(map(int, input().split())) for _ in range(M)]

# 逆元を利用してcomb(nCk), perm(nPk)をO(1)計算

MOD = 10 ** 9 + 7

num = 2 * N + 1
fac = [1] * (num + 1)
inv = [1] * (num + 1)
for j in range(1, num + 1):
    fac[j] = (fac[j - 1] * j) % MOD

inv[num] = pow(fac[num], MOD-2, MOD)
for j in range(num - 1, -1, -1):
    inv[j] = (inv[j + 1] * (j + 1)) % MOD


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return (fac[n] * inv[n - r] * inv[r]) % MOD


def perm(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return comb(n, r) * fac[r] % MOD


ans = comb(2 * N, N) * 2 * N

for t, x, y in TXY:
    if t == 1:
        ans -= comb(x + y, x) * comb(2 * N - (x + y) - 1, N - y)
    else:
        ans -= comb(x + y, x) * comb(2 * N - (x + y) - 1, N - x)
    ans %= MOD

print(ans)
0