結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 rin204rin204
提出日時 2021-07-09 22:01:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 85,316 KB
最終ジャッジ日時 2023-09-14 09:02:48
合計ジャッジ時間 4,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 84 ms
83,836 KB
testcase_02 AC 223 ms
85,220 KB
testcase_03 AC 229 ms
85,260 KB
testcase_04 AC 227 ms
85,244 KB
testcase_05 AC 229 ms
85,220 KB
testcase_06 AC 227 ms
85,304 KB
testcase_07 AC 232 ms
85,228 KB
testcase_08 AC 233 ms
85,228 KB
testcase_09 AC 233 ms
85,228 KB
testcase_10 AC 228 ms
85,316 KB
testcase_11 AC 205 ms
85,264 KB
testcase_12 AC 202 ms
85,100 KB
testcase_13 AC 202 ms
85,276 KB
testcase_14 AC 85 ms
83,916 KB
testcase_15 AC 86 ms
84,056 KB
testcase_16 AC 86 ms
84,136 KB
testcase_17 AC 85 ms
83,764 KB
testcase_18 AC 85 ms
83,788 KB
testcase_19 AC 85 ms
83,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
N = 500000
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD

def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return (fact[n] * invfact[k] % MOD) * invfact[n - k] % MOD

def nHk(n, k):
    return nCk(n + k - 1, k)
    
n, m = map(int, input().split())
ans = nCk(2 * n, n) * 2 * n
for _ in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        ans -= nCk(x + y, x) * nCk(2 * n - (x + y + 1), n - y)
    else:
        ans -= nCk(x + y, x) * nCk(2 * n - (x + y + 1), n - x)
    ans %= MOD
print(ans)
0