結果

問題 No.1785 Inequality Signs
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-12-12 22:46:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 1,501 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 90,904 KB
最終ジャッジ日時 2023-09-30 05:31:45
合計ジャッジ時間 23,208 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
80,048 KB
testcase_01 AC 348 ms
85,688 KB
testcase_02 AC 481 ms
90,120 KB
testcase_03 AC 486 ms
87,972 KB
testcase_04 AC 212 ms
83,544 KB
testcase_05 AC 355 ms
87,048 KB
testcase_06 AC 486 ms
86,432 KB
testcase_07 AC 230 ms
83,736 KB
testcase_08 AC 454 ms
86,488 KB
testcase_09 AC 270 ms
84,676 KB
testcase_10 AC 457 ms
89,196 KB
testcase_11 AC 338 ms
86,664 KB
testcase_12 AC 335 ms
87,260 KB
testcase_13 AC 298 ms
84,708 KB
testcase_14 AC 416 ms
89,004 KB
testcase_15 AC 340 ms
86,420 KB
testcase_16 AC 308 ms
86,092 KB
testcase_17 AC 419 ms
89,392 KB
testcase_18 AC 398 ms
88,136 KB
testcase_19 AC 374 ms
87,124 KB
testcase_20 AC 409 ms
87,748 KB
testcase_21 AC 373 ms
87,400 KB
testcase_22 AC 335 ms
86,212 KB
testcase_23 AC 322 ms
86,252 KB
testcase_24 AC 502 ms
88,632 KB
testcase_25 AC 357 ms
86,836 KB
testcase_26 AC 408 ms
87,912 KB
testcase_27 AC 567 ms
87,288 KB
testcase_28 AC 469 ms
86,952 KB
testcase_29 AC 454 ms
87,324 KB
testcase_30 AC 495 ms
87,760 KB
testcase_31 AC 470 ms
87,412 KB
testcase_32 AC 487 ms
87,196 KB
testcase_33 AC 138 ms
80,148 KB
testcase_34 AC 294 ms
86,400 KB
testcase_35 AC 366 ms
86,600 KB
testcase_36 AC 507 ms
88,792 KB
testcase_37 AC 504 ms
89,944 KB
testcase_38 AC 492 ms
87,720 KB
testcase_39 AC 341 ms
86,152 KB
testcase_40 AC 390 ms
87,752 KB
testcase_41 AC 433 ms
89,800 KB
testcase_42 AC 503 ms
88,900 KB
testcase_43 AC 549 ms
89,520 KB
testcase_44 AC 478 ms
89,032 KB
testcase_45 AC 374 ms
86,984 KB
testcase_46 AC 516 ms
88,256 KB
testcase_47 AC 481 ms
90,860 KB
testcase_48 AC 458 ms
90,904 KB
testcase_49 AC 263 ms
84,544 KB
testcase_50 AC 490 ms
88,384 KB
testcase_51 AC 281 ms
85,332 KB
testcase_52 AC 241 ms
84,624 KB
testcase_53 AC 271 ms
85,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combinatorics:
	def __init__(self, n: int, mod: int) -> None:
		self.n = n
		self.mod = mod
		self.fa = [1] * (self.n + 1)
		self.fi = [1] * (self.n + 1)

		for i in range(1, self.n + 1):
			self.fa[i] = self.fa[i - 1] * i % self.mod

		self.fi[-1] = pow(self.fa[-1], self.mod - 2, self.mod)

		for i in range(self.n, 0, -1):
			self.fi[i - 1] = self.fi[i] * i % self.mod

	def comb(self, n: int, r: int) -> int:
		if n < r:return 0
		if n < 0 or r < 0:return 0
		return self.fa[n] * self.fi[r] % self.mod * self.fi[n - r] % self.mod

	def perm(self, n: int, r: int) -> int:
		if n < r:return 0
		if n < 0 or r < 0:return 0
		return self.fa[n] * self.fi[n - r] % self.mod
		
	def combr(self, n: int, r: int) -> int:
		if n == r == 0:return 1
		return self.comb(n + r - 1, r)
import typing
# 拡張Euclidの互除法
def extgcd(a: int, b: int, d: int = 0) -> typing.Tuple[int, int, int]:
	g = a
	if b == 0:
		x, y = 1, 0
	else:
		x, y, g = extgcd(b, a % b)
		x, y = y, x - a // b * y
	return x, y, g
 
# mod p における逆元
def invmod(a: int, p: int) -> int:
	x, y, g = extgcd(a, p)
	x %= p
	return x
n, k = map(int, input().split())
mod = 10 ** 9 + 7
C = Combinatorics(n, mod)
cnt = 1
for i in range(1, n + 1):
	cnt *= (k - i + 1)
	cnt *= invmod(i, mod)
	cnt %= mod
if k < n: cnt = 0
ans = 0
ans += cnt * C.comb(n - 1, 0)
for i in range(1, n + 1):
	cnt *= k + i
	cnt *= invmod(k + i - n, mod)
	cnt %= mod
	if k + i == n: cnt = 1
	ans += cnt * C.comb(n - 1, i)
	ans %= mod
print(ans % (mod))
0