結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 tamatotamato
提出日時 2021-07-09 21:35:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 87,172 KB
最終ジャッジ日時 2023-09-14 07:58:27
合計ジャッジ時間 4,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
85,664 KB
testcase_01 AC 95 ms
85,796 KB
testcase_02 AC 187 ms
87,124 KB
testcase_03 AC 186 ms
87,172 KB
testcase_04 AC 191 ms
87,140 KB
testcase_05 AC 179 ms
87,024 KB
testcase_06 AC 179 ms
86,904 KB
testcase_07 AC 178 ms
86,780 KB
testcase_08 AC 174 ms
86,664 KB
testcase_09 AC 172 ms
86,732 KB
testcase_10 AC 175 ms
87,140 KB
testcase_11 AC 160 ms
87,084 KB
testcase_12 AC 160 ms
87,172 KB
testcase_13 AC 155 ms
87,048 KB
testcase_14 AC 94 ms
85,760 KB
testcase_15 AC 92 ms
85,748 KB
testcase_16 AC 95 ms
85,736 KB
testcase_17 AC 93 ms
85,752 KB
testcase_18 AC 94 ms
85,828 KB
testcase_19 AC 94 ms
85,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 4 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    N, M = map(int, input().split())
    ans = (comb(2*N, N) * (2*N))%mod
    for _ in range(M):
        t, h, w = map(int, input().split())
        if t == 1:
            ans = (ans - (comb(h+w, h) * comb((N - (h+1) + N - w), N-w))%mod)%mod
        else:
            ans = (ans - (comb(h + w, h) * comb((N - h + N - (w+1)), N - h)) % mod) % mod
    print(ans)


if __name__ == '__main__':
    main()
0