結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー stngstng
提出日時 2021-07-18 16:15:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 86,596 KB
実行使用メモリ 185,168 KB
最終ジャッジ日時 2023-09-22 18:32:41
合計ジャッジ時間 9,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
163,624 KB
testcase_01 AC 156 ms
163,668 KB
testcase_02 AC 421 ms
184,260 KB
testcase_03 AC 431 ms
184,600 KB
testcase_04 AC 432 ms
184,684 KB
testcase_05 AC 406 ms
184,864 KB
testcase_06 AC 419 ms
184,760 KB
testcase_07 AC 415 ms
184,732 KB
testcase_08 AC 405 ms
184,208 KB
testcase_09 AC 411 ms
184,268 KB
testcase_10 AC 405 ms
184,352 KB
testcase_11 AC 416 ms
184,844 KB
testcase_12 AC 414 ms
185,168 KB
testcase_13 AC 405 ms
184,904 KB
testcase_14 AC 70 ms
71,140 KB
testcase_15 AC 70 ms
71,108 KB
testcase_16 AC 70 ms
71,236 KB
testcase_17 AC 70 ms
71,336 KB
testcase_18 AC 70 ms
71,292 KB
testcase_19 AC 70 ms
71,144 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

n,m = map(int,input().split())
txy = [[int(i) for i in input().split()] for j in range(m)]

N = 2*n

mod = 10**9+7 #出力の制限
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 )

a = cmb(N,n,mod)
ans = a*N
ans %= mod

for i in range(m):
    bfr = cmb(txy[i][1]+txy[i][2],txy[i][1],mod)
    bfr %= mod
    if txy[i][0] == 1:
        txy[i][1] += 1
    else:
        txy[i][2] += 1
    wa = txy[i][1]+txy[i][2]
    ngs = N - (wa)
    tate = n - txy[i][1]
    aft = cmb(ngs,tate,mod)
    aft %= mod
    ans -= (bfr*aft) % mod
    ans %= mod

print(ans%mod)
0