結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shinichishinichi
提出日時 2021-09-29 16:54:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 850 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 43,368 KB
最終ジャッジ日時 2023-09-23 12:52:26
合計ジャッジ時間 9,691 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 377 ms
43,240 KB
testcase_15 AC 374 ms
43,308 KB
testcase_16 AC 374 ms
43,236 KB
testcase_17 AC 391 ms
43,228 KB
testcase_18 AC 378 ms
43,300 KB
testcase_19 AC 383 ms
43,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 3 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())

total = cmb(2*N, N, mod) * 2 * N
for _ in range(M):
    t, x, y = map(int, input().split())
    road = 2 * N - (x + y + 1)
    if t == 1:
        value1 = cmb(x+y, x, mod)
        value2 = cmb(road, N-y, mod)

    else:
        value1 = cmb(x+y, x, mod)
        value2 = cmb(road, N-x, mod)
    total -= value1 * value2
    total %= mod
print(total)




0