結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー rlangevin
提出日時 2023-07-15 11:37:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 204,804 KB
最終ジャッジ日時 2024-09-16 19:58:21
合計ジャッジ時間 18,487 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 99
権限があれば一括ダウンロードができます

ソースコード

diff #

M = int(input())
H = list(map(int, input().split()))
if H == [0]:
    print(1)
    exit()
N = len(H)

mod = 10 ** 9 + 7
n = 5050505
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


nokori = M - sum(H) - (N - 1)
if nokori < 0:
    print("NA")
    exit()
print(comb(N + nokori, nokori))
0