結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shinichishinichi
提出日時 2021-09-29 16:55:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 66,896 KB
最終ジャッジ日時 2023-09-23 12:53:55
合計ジャッジ時間 28,834 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 633 ms
66,880 KB
testcase_02 AC 1,812 ms
66,876 KB
testcase_03 AC 1,821 ms
66,836 KB
testcase_04 AC 1,835 ms
66,832 KB
testcase_05 AC 1,858 ms
66,712 KB
testcase_06 AC 1,842 ms
66,832 KB
testcase_07 AC 1,831 ms
66,888 KB
testcase_08 AC 1,829 ms
66,708 KB
testcase_09 AC 1,837 ms
66,800 KB
testcase_10 AC 1,842 ms
66,884 KB
testcase_11 AC 1,589 ms
66,728 KB
testcase_12 AC 1,613 ms
66,800 KB
testcase_13 AC 1,598 ms
66,896 KB
testcase_14 AC 648 ms
66,776 KB
testcase_15 AC 636 ms
66,720 KB
testcase_16 AC 618 ms
66,824 KB
testcase_17 AC 631 ms
66,800 KB
testcase_18 AC 626 ms
66,736 KB
testcase_19 AC 650 ms
66,820 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)




0