結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shinichishinichi
提出日時 2021-09-29 16:56:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 189,684 KB
最終ジャッジ日時 2023-09-23 12:54:08
合計ジャッジ時間 7,976 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
187,924 KB
testcase_01 AC 179 ms
187,892 KB
testcase_02 AC 405 ms
189,572 KB
testcase_03 AC 402 ms
189,484 KB
testcase_04 AC 399 ms
189,304 KB
testcase_05 AC 389 ms
189,536 KB
testcase_06 AC 393 ms
189,320 KB
testcase_07 AC 386 ms
189,296 KB
testcase_08 AC 391 ms
189,384 KB
testcase_09 AC 394 ms
189,664 KB
testcase_10 AC 388 ms
189,684 KB
testcase_11 AC 361 ms
189,400 KB
testcase_12 AC 366 ms
189,472 KB
testcase_13 AC 350 ms
189,568 KB
testcase_14 AC 179 ms
188,004 KB
testcase_15 AC 181 ms
187,800 KB
testcase_16 AC 180 ms
187,796 KB
testcase_17 AC 181 ms
187,780 KB
testcase_18 AC 181 ms
187,948 KB
testcase_19 AC 183 ms
188,168 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 = 5 * 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 % mod)




0