結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | moharan627 |
提出日時 | 2021-08-05 20:51:10 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,965 ms / 2,000 ms |
コード長 | 1,388 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 10,908 KB |
実行使用メモリ | 27,844 KB |
最終ジャッジ日時 | 2023-10-14 21:40:57 |
合計ジャッジ時間 | 25,232 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 105 ms
27,736 KB |
testcase_01 | AC | 105 ms
27,680 KB |
testcase_02 | AC | 1,948 ms
27,768 KB |
testcase_03 | AC | 1,930 ms
27,764 KB |
testcase_04 | AC | 1,924 ms
27,712 KB |
testcase_05 | AC | 1,934 ms
27,824 KB |
testcase_06 | AC | 1,931 ms
27,736 KB |
testcase_07 | AC | 1,965 ms
27,820 KB |
testcase_08 | AC | 1,927 ms
27,700 KB |
testcase_09 | AC | 1,916 ms
27,768 KB |
testcase_10 | AC | 1,928 ms
27,668 KB |
testcase_11 | AC | 1,749 ms
27,844 KB |
testcase_12 | AC | 1,722 ms
27,756 KB |
testcase_13 | AC | 1,714 ms
27,712 KB |
testcase_14 | AC | 104 ms
27,712 KB |
testcase_15 | AC | 103 ms
27,668 KB |
testcase_16 | AC | 104 ms
27,664 KB |
testcase_17 | AC | 104 ms
27,820 KB |
testcase_18 | AC | 105 ms
27,672 KB |
testcase_19 | AC | 104 ms
27,660 KB |
ソースコード
import sys INF = float('inf') #10**20,2**63,float('inf') MOD = 10**9 + 7 MOD2 = 998244353 #from collections import defaultdict def solve(): def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(input()) def IC(): return [int(c) for c in input()] def MI(): return map(int, sys.stdin.readline().split()) N,M = MI() def modinv(x): return pow(x, MOD - 2, MOD) MAX = 500050 Fact = [0]*MAX Fact[0] = 1 Fact[1] = 1 for n in range(2,MAX): Fact[n] = (n*(Fact[n-1]))%MOD #print((Fact[N+K]*modinv(Fact[N]*Fact[K])) % MOD) All = Fact[2*N]*modinv(Fact[N]*Fact[N]) % MOD All *= (2*N) All %= MOD #print(All) for _ in range(M): T,X,Y = MI() Bef = Fact[X+Y]*modinv(Fact[X]*Fact[Y])%MOD Up = N-X Right = N-Y if T==1: #print(Fact[(Up-1)+Right]*modinv(Fact[Up-1]*Fact[Right]) % MOD) All-= Bef*(Fact[(Up-1)+Right]*modinv(Fact[Up-1]*Fact[Right])) All %= MOD else: #print(Fact[Up+ Right-1] * modinv(Fact[Up] * Fact[Right-1]) % MOD) All -= Bef*(Fact[Up+ Right-1] * modinv(Fact[Up] * Fact[Right-1])) All %= MOD print(All) return solve() #sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!