結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 H20H20
提出日時 2021-07-09 22:58:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 165,936 KB
最終ジャッジ日時 2023-09-14 10:30:29
合計ジャッジ時間 7,565 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
163,964 KB
testcase_01 AC 165 ms
164,172 KB
testcase_02 AC 389 ms
165,780 KB
testcase_03 AC 384 ms
165,756 KB
testcase_04 AC 388 ms
165,724 KB
testcase_05 AC 379 ms
165,936 KB
testcase_06 AC 386 ms
165,684 KB
testcase_07 AC 379 ms
165,808 KB
testcase_08 AC 375 ms
165,848 KB
testcase_09 AC 383 ms
165,756 KB
testcase_10 AC 382 ms
165,820 KB
testcase_11 AC 330 ms
165,488 KB
testcase_12 AC 331 ms
165,896 KB
testcase_13 AC 335 ms
165,844 KB
testcase_14 AC 165 ms
163,968 KB
testcase_15 AC 165 ms
164,204 KB
testcase_16 AC 165 ms
164,332 KB
testcase_17 AC 162 ms
164,064 KB
testcase_18 AC 164 ms
164,008 KB
testcase_19 AC 164 ms
164,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int, input().split())
mod = 10**9+7

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9+7
N = 400000  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ANS = 2*n*fact[2*n]*factinv[n]*factinv[n]%mod

for _ in range(m):
    t,x,y = map(int, input().split())
    TEMP = fact[x+y]*factinv[x]*factinv[y]%mod
    if t==1:
        TEMP = TEMP*fact[2*n-(x+y+1)]*factinv[n-x-1]*factinv[n-y]%mod
    else:
        TEMP = TEMP*fact[2*n-(x+y+1)]*factinv[n-x]*factinv[n-y-1]%mod

    ANS = (ANS-TEMP)%mod
print(ANS)
0