結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ntudantuda
提出日時 2021-07-22 18:59:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,582 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 71,052 KB
最終ジャッジ日時 2023-09-24 14:23:00
合計ジャッジ時間 20,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 425 ms
31,428 KB
testcase_01 AC 422 ms
31,456 KB
testcase_02 AC 1,582 ms
70,856 KB
testcase_03 AC 1,577 ms
70,960 KB
testcase_04 AC 1,580 ms
70,940 KB
testcase_05 AC 1,562 ms
70,992 KB
testcase_06 AC 1,573 ms
70,820 KB
testcase_07 AC 1,565 ms
71,052 KB
testcase_08 AC 1,562 ms
70,984 KB
testcase_09 AC 1,562 ms
70,864 KB
testcase_10 AC 1,563 ms
70,820 KB
testcase_11 AC 1,307 ms
70,988 KB
testcase_12 AC 1,313 ms
71,032 KB
testcase_13 AC 1,313 ms
71,040 KB
testcase_14 AC 16 ms
7,872 KB
testcase_15 AC 16 ms
7,940 KB
testcase_16 AC 16 ms
7,940 KB
testcase_17 AC 16 ms
7,792 KB
testcase_18 AC 16 ms
7,780 KB
testcase_19 AC 17 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
TXY = [list(map(int,input().split())) for _ in range(M)]

mod = 10 ** 9 + 7

L1 = [1] * (N * 2 + 1)
L2 = [1] * (N + 1)

for i in range(2,N*2+1):
    L1[i] = (i*L1[i-1]) % mod
for i in range(2,N+1):
    L2[i] = (L2[i-1] * pow(i,-1,mod)) % mod

ans =  (L1[2 * N] * L2[N] * L2[N] * (2*N)) % mod
for txy in TXY:
    t,x,y = txy
    temp = (L1[x+y] * L2[x] * L2[y])%mod
    if t == 1:
        temp = (temp*L1[2*N-x-y-1] * L2[N-x-1] * L2[N-y])%mod
    else:
        temp = (temp*L1[2*N-x-y-1] * L2[N-x] * L2[N-y-1])%mod
    ans = (ans-temp)%mod
print(ans)

0