結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ProgrammerryokiProgrammerryoki
提出日時 2021-07-09 23:38:31
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2023-09-14 10:58:53
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
8,420 KB
testcase_01 WA -
testcase_02 TLE -
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
S = binomial_coefficients(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