結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 rin204rin204
提出日時 2021-07-09 23:48:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 85,592 KB
最終ジャッジ日時 2023-09-14 11:15:03
合計ジャッジ時間 5,165 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
84,104 KB
testcase_01 AC 87 ms
83,888 KB
testcase_02 AC 244 ms
85,280 KB
testcase_03 AC 243 ms
85,592 KB
testcase_04 AC 241 ms
85,412 KB
testcase_05 AC 245 ms
85,236 KB
testcase_06 AC 245 ms
85,368 KB
testcase_07 AC 246 ms
85,140 KB
testcase_08 AC 243 ms
85,424 KB
testcase_09 AC 246 ms
85,496 KB
testcase_10 AC 241 ms
85,376 KB
testcase_11 AC 211 ms
85,364 KB
testcase_12 AC 212 ms
85,452 KB
testcase_13 AC 207 ms
85,436 KB
testcase_14 AC 86 ms
84,260 KB
testcase_15 AC 88 ms
84,048 KB
testcase_16 AC 87 ms
83,996 KB
testcase_17 AC 89 ms
83,976 KB
testcase_18 AC 90 ms
84,260 KB
testcase_19 AC 89 ms
84,052 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 % MOD
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