結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shinichishinichi
提出日時 2021-09-29 16:54:06
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 846 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 138,872 KB
最終ジャッジ日時 2023-09-23 12:51:08
合計ジャッジ時間 7,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 143 ms
137,552 KB
testcase_15 AC 145 ms
137,140 KB
testcase_16 AC 145 ms
137,252 KB
testcase_17 AC 146 ms
137,328 KB
testcase_18 AC 144 ms
137,132 KB
testcase_19 AC 140 ms
137,104 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