結果

問題 No.1785 Inequality Signs
ユーザー lloyzlloyz
提出日時 2021-12-20 00:14:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 513 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 86,560 KB
実行使用メモリ 90,948 KB
最終ジャッジ日時 2023-10-13 19:16:52
合計ジャッジ時間 15,795 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,072 KB
testcase_01 AC 184 ms
80,080 KB
testcase_02 AC 304 ms
84,624 KB
testcase_03 AC 307 ms
82,108 KB
testcase_04 AC 111 ms
77,728 KB
testcase_05 AC 238 ms
82,000 KB
testcase_06 AC 315 ms
82,100 KB
testcase_07 AC 116 ms
77,504 KB
testcase_08 AC 284 ms
81,124 KB
testcase_09 AC 145 ms
78,376 KB
testcase_10 AC 334 ms
86,408 KB
testcase_11 AC 151 ms
78,812 KB
testcase_12 AC 237 ms
81,052 KB
testcase_13 AC 144 ms
78,896 KB
testcase_14 AC 268 ms
82,852 KB
testcase_15 AC 191 ms
80,816 KB
testcase_16 AC 176 ms
80,924 KB
testcase_17 AC 323 ms
84,724 KB
testcase_18 AC 241 ms
82,532 KB
testcase_19 AC 224 ms
81,780 KB
testcase_20 AC 227 ms
81,896 KB
testcase_21 AC 214 ms
81,608 KB
testcase_22 AC 235 ms
81,904 KB
testcase_23 AC 199 ms
80,404 KB
testcase_24 AC 344 ms
82,612 KB
testcase_25 AC 227 ms
81,332 KB
testcase_26 AC 277 ms
82,872 KB
testcase_27 AC 286 ms
82,596 KB
testcase_28 AC 296 ms
82,408 KB
testcase_29 AC 317 ms
82,584 KB
testcase_30 AC 513 ms
90,948 KB
testcase_31 AC 278 ms
82,040 KB
testcase_32 AC 302 ms
83,372 KB
testcase_33 AC 69 ms
71,140 KB
testcase_34 AC 132 ms
78,156 KB
testcase_35 AC 121 ms
79,328 KB
testcase_36 AC 223 ms
82,624 KB
testcase_37 AC 159 ms
82,988 KB
testcase_38 AC 159 ms
82,064 KB
testcase_39 AC 163 ms
81,156 KB
testcase_40 AC 172 ms
82,044 KB
testcase_41 AC 187 ms
83,836 KB
testcase_42 AC 234 ms
83,104 KB
testcase_43 AC 274 ms
83,284 KB
testcase_44 AC 250 ms
82,320 KB
testcase_45 AC 154 ms
81,708 KB
testcase_46 AC 165 ms
82,432 KB
testcase_47 AC 160 ms
83,532 KB
testcase_48 AC 187 ms
84,856 KB
testcase_49 AC 112 ms
77,884 KB
testcase_50 AC 246 ms
82,512 KB
testcase_51 AC 144 ms
78,960 KB
testcase_52 AC 137 ms
78,788 KB
testcase_53 AC 150 ms
79,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
mod = 10**9 + 7

# nは任意の数に置き換え可能
fact = [1] * (n + 1)
inv = [1] * (n + 1)
finv = [1] * (n + 1)
for i in range(2, n + 1):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

def comb(a, b):
    return fact[a] * finv[b] * finv[a - b] % mod
def extgcd(a, b):
    if b != 0:
        d, y, x = extgcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0
def inverse(a, m):
    d, x, _ = extgcd(a, m)
    if d != 1:
        return -1
    return x % m

ans = 0
cnt = 1
if k >= n:
    for i in range(1, n + 1):
        cnt *= k - i + 1
        cnt *= inv[i]
        cnt %= mod
    ans += cnt

for i in range(1, n):
    if k + i > n:
        cnt *= k + i
        cnt *= inverse(k + i - n, mod)
        cnt %= mod
        ans += cnt * comb(n - 1, i) % mod
        ans %= mod
    elif k + i == n:
        ans += cnt * comb(n - 1, i) % mod
        ans %= mod
print(ans)
0