結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shotoyooshotoyoo
提出日時 2021-07-09 21:37:55
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 273 ms
使用メモリ 91,864 KB
最終ジャッジ日時 2023-02-01 22:28:24
合計ジャッジ時間 5,997 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 111 ms
89,976 KB
testcase_01 AC 109 ms
90,072 KB
testcase_02 AC 245 ms
91,368 KB
testcase_03 AC 241 ms
91,060 KB
testcase_04 AC 246 ms
91,268 KB
testcase_05 AC 232 ms
91,428 KB
testcase_06 AC 237 ms
91,192 KB
testcase_07 AC 229 ms
91,464 KB
testcase_08 AC 229 ms
90,828 KB
testcase_09 AC 231 ms
90,984 KB
testcase_10 AC 231 ms
90,972 KB
testcase_11 AC 225 ms
91,504 KB
testcase_12 AC 226 ms
91,768 KB
testcase_13 AC 225 ms
91,864 KB
testcase_14 AC 83 ms
75,288 KB
testcase_15 AC 82 ms
75,536 KB
testcase_16 AC 81 ms
75,652 KB
testcase_17 AC 82 ms
75,700 KB
testcase_18 AC 81 ms
75,572 KB
testcase_19 AC 84 ms
75,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,m = list(map(int, input().split()))
### 素数の逆元とCombination

M = 10**9+7 # 出力の制限
N = 2*n+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M
ans = 2*n*cmb(2*n,n)%M
for i in range(m):
    t,x,y = map(int, input().split())
    if t==1:
        ans -= cmb(x+y,x) * cmb(2*n - x - y - 1, n-x-1) % M
    else:
        ans -= cmb(x+y,x) * cmb(2*n - x - y - 1, n-y-1) % M
    ans %= M
print(ans%M)
0