結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-07-09 23:35:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 627 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 84,220 KB
最終ジャッジ日時 2023-09-14 10:56:35
合計ジャッジ時間 9,402 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 354 ms
82,348 KB
testcase_01 AC 351 ms
82,380 KB
testcase_02 AC 534 ms
84,184 KB
testcase_03 AC 539 ms
83,912 KB
testcase_04 AC 533 ms
84,036 KB
testcase_05 AC 528 ms
83,892 KB
testcase_06 AC 523 ms
83,884 KB
testcase_07 AC 522 ms
83,896 KB
testcase_08 AC 520 ms
83,660 KB
testcase_09 AC 530 ms
83,960 KB
testcase_10 AC 520 ms
83,588 KB
testcase_11 AC 496 ms
83,920 KB
testcase_12 AC 493 ms
84,004 KB
testcase_13 AC 487 ms
84,220 KB
testcase_14 AC 71 ms
71,464 KB
testcase_15 AC 71 ms
71,136 KB
testcase_16 AC 71 ms
71,100 KB
testcase_17 AC 70 ms
71,404 KB
testcase_18 AC 71 ms
71,096 KB
testcase_19 AC 71 ms
71,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
n *= 2
fac_arr = [1] * (n+1)
r_s_fac_arr = [1] * (n+1)
mod = 10 ** 9 + 7
for i in range(1,n+1):
    fac_arr[i] = (fac_arr[i-1] % mod) * i % mod
    r_s_fac_arr[i] = (r_s_fac_arr[i-1] % mod) * pow(i,mod-2,mod) % mod 
def nckMod(n,k):
    return fac_arr[n]  % mod *  r_s_fac_arr[k] % mod * r_s_fac_arr[n-k] % mod
ans = nckMod(n,n//2) * n
n //= 2
for i in range(m):
    t,x,y = map(int,input().split())
    n1 ,c1 = x + y,min(x,y)
    if t == 1:
        n2,c2 = n - (x + 1) + n - y  , n-y
    else:
        n2,c2 = n - (y + 1) + n - x  , n-x
    ans -= nckMod(n1,c1) * nckMod(n2,c2)
print(ans % mod)
0