結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー むらため
提出日時 2019-01-27 18:31:21
言語 Nim
(2.2.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 3,358 ms
コンパイル使用メモリ 65,864 KB
実行使用メモリ 30,348 KB
最終ジャッジ日時 2024-07-01 11:02:38
合計ジャッジ時間 7,081 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 50 RE * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import sequtils,algorithm,math,strutils
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

const MOD = 1_000_000_007
proc combinationWithMod(n,k:int):int = # nCk を剰余ありで
  result = 1
  let x = k.max(n - k)
  let y = k.min(n - k)
  var req = 1
  for i in 1..y: req *= i
  for i in 1..y:
    var m = n+1-i
    let g = m.gcd(req)
    m = m div g
    req = req div g
    result = (result * m) mod MOD


proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

let m = scan()
let H = stdin.readLine().split().map(parseInt)
if H.len == 1 :
  if H[0] == 0: quit "1",0
let n = m - (H.sum() - H.len)
let h = H.len()
let k = n - (h + h - 1)
if k < 0: quit "NA",0
if k == 0 : quit "1",0
# h箇所にk個入れる組み合わせ
echo (h+k).combinationWithMod(h)
0