結果

問題 No.1785 Inequality Signs
ユーザー lloyzlloyz
提出日時 2021-12-20 00:10:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,021 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 91,332 KB
最終ジャッジ日時 2023-10-13 19:12:30
合計ジャッジ時間 16,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,384 KB
testcase_01 AC 194 ms
80,564 KB
testcase_02 AC 314 ms
84,904 KB
testcase_03 AC 314 ms
82,592 KB
testcase_04 AC 114 ms
77,976 KB
testcase_05 AC 246 ms
82,344 KB
testcase_06 AC 320 ms
82,496 KB
testcase_07 AC 123 ms
77,684 KB
testcase_08 AC 293 ms
81,824 KB
testcase_09 AC 151 ms
78,656 KB
testcase_10 AC 348 ms
86,620 KB
testcase_11 AC 158 ms
78,996 KB
testcase_12 AC 250 ms
81,372 KB
testcase_13 AC 153 ms
79,056 KB
testcase_14 AC 283 ms
83,100 KB
testcase_15 AC 203 ms
81,208 KB
testcase_16 AC 179 ms
81,188 KB
testcase_17 AC 338 ms
85,056 KB
testcase_18 AC 253 ms
83,012 KB
testcase_19 AC 233 ms
81,884 KB
testcase_20 AC 240 ms
82,280 KB
testcase_21 AC 233 ms
81,828 KB
testcase_22 AC 250 ms
82,528 KB
testcase_23 AC 210 ms
80,812 KB
testcase_24 AC 364 ms
83,096 KB
testcase_25 AC 238 ms
81,616 KB
testcase_26 AC 286 ms
83,152 KB
testcase_27 AC 290 ms
82,932 KB
testcase_28 AC 304 ms
82,896 KB
testcase_29 AC 315 ms
82,808 KB
testcase_30 AC 532 ms
91,332 KB
testcase_31 AC 288 ms
82,344 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 136 ms
78,424 KB
testcase_35 AC 125 ms
79,684 KB
testcase_36 AC 230 ms
82,688 KB
testcase_37 AC 163 ms
83,076 KB
testcase_38 AC 162 ms
82,632 KB
testcase_39 AC 164 ms
81,164 KB
testcase_40 AC 173 ms
82,020 KB
testcase_41 AC 188 ms
84,192 KB
testcase_42 AC 238 ms
83,604 KB
testcase_43 AC 282 ms
83,336 KB
testcase_44 AC 258 ms
82,852 KB
testcase_45 AC 158 ms
81,888 KB
testcase_46 AC 167 ms
82,632 KB
testcase_47 AC 167 ms
83,640 KB
testcase_48 AC 195 ms
85,060 KB
testcase_49 AC 115 ms
78,288 KB
testcase_50 AC 256 ms
82,656 KB
testcase_51 AC 150 ms
79,104 KB
testcase_52 AC 141 ms
79,236 KB
testcase_53 AC 155 ms
79,844 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 - 1 >= 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