結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ProgrammerryokiProgrammerryoki
提出日時 2021-07-09 23:03:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,155 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,744 KB
実行使用メモリ 8,904 KB
最終ジャッジ日時 2023-09-14 10:35:06
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = [int(i) for i in input().split()]

mod = 10**9 + 7

def power(x, a):
    if a == 0:
        return 1
    elif a == 1:
        return x
    elif a % 2 == 0:
        return power(x, a//2) **2 % mod
    else:
        return power(x, a//2) **2 * x % mod

def modinv(x):
    return power(x, mod-2)

def binomial_coefficients(n, k):
    numera = 1  # 分子
    denomi = 1  # 分母

    for i in range(k):
        numera *= n-i
        numera %= mod
        denomi *= i+1
        denomi %= mod
    return (numera * modinv(denomi)) % mod

from math import comb

S = comb(2*N, N) * 2 * N
# print(S)
for _ in range(M):
    t,x,y = [int(i) for i in input().split()]
    # S -= comb(2*N - (x+y+1), min(N-(x+1), N-(y+1)))
    if t == 1:
    #     # S -= binomial_coefficients(2*N - (x+y+1), min(N-(x+1), N-(y+1)))
        S -= comb(2*N - (x+y+1), N-(x+1))
    #     print(2*N - (x+y+1), min(N-(x+1), N-(y+1)))
    elif t == 2:
    #     # S -= binomial_coefficients(2*N - (x+y+1), N-(y+1))
        S -= comb(2*N - (x+y+1), N-(y+1))
    #     print(2*N - (x+y+1), N-(y+1))
    # print(2*N - (x+y+1), N-y+1, N-x+1, t)
    # S %= mod
    # print(S)
print(S % mod)
0