結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー airis
提出日時 2016-07-09 02:46:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 39,188 KB
最終ジャッジ日時 2024-10-13 08:03:27
合計ジャッジ時間 17,656 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 99
権限があれば一括ダウンロードができます

ソースコード

diff #

M = input()
H = map(int, raw_input().split())
H = filter(lambda x: x > 0, H)

ans = 0
mod = int(1e+9 + 7)
fact = [0] * (10**6 + 10)
fact[0] = 1

S = sum(H)
n = len(H)


def powmod(x, p):
  res = 1
  tmp = x
  while p > 0:
    if p & 1:
      res *= tmp
      res %= mod
    tmp = tmp * tmp
    tmp %= mod;
    p = p >> 1;
  return res


for i in xrange(M + 5):
  fact[i + 1] = (i + 1) * fact[i]
  fact[i + 1] %= mod;

if S + (n - 1) > M:
  print "NA"
else:
  a = fact[M - S + 1]
  b = fact[n]
  c = fact[M - S + 1 - n]

  ans = a * powmod((b * c) % mod, mod - 2)
  ans %= mod

  print ans

0