結果
問題 |
No.1596 Distance Sum in 2D Plane
|
ユーザー |
![]() |
提出日時 | 2024-09-23 17:09:15 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 843 bytes |
コンパイル時間 | 4,592 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 116,888 KB |
最終ジャッジ日時 | 2024-09-23 17:16:44 |
合計ジャッジ時間 | 16,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 RE * 14 |
ソースコード
class CP: def __init__(self, N): self.fact = [1] self.fact_inv = [1] for i in range(1, N+1): self.fact.append((self.fact[-1]*i)%MOD) self.fact_inv.append(pow(self.fact[-1], -1, MOD)) def C(self, N, K): if N >= K: return self.fact[N]*self.fact_inv[K]%MOD*self.fact_inv[N-K]%MOD else: return 0 def P(self, N, K): if N >= K: return self.fact[N]*self.fact_inv[N-K]%MOD else: return 0 N, M = map(int, input().split()) free = [list(map(int, input().split())) for _ in range(M)] MOD = 10**9+7 cp = CP(10**5*2) ans = cp.C(N*2, N)*(N*2) for t, x, y in free: if t == 1: nx, ny = N-x-1, N-y else: nx, ny = N-x, N-y-1 ans -= cp.C(x+y, x)*cp.C(nx+ny, nx)%MOD ans %= MOD print(ans)