結果

問題 No.4 おもりと天秤
ユーザー むらためむらため
提出日時 2017-07-30 10:19:32
言語 Nim
(2.0.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,530 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 60,908 KB
最終ジャッジ日時 2023-09-12 13:47:23
合計ジャッジ時間 1,287 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(21, 1) template/generic instantiation of `main` from here
/home/judge/data/code/Main.nim(2, 52) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(21, 1) template/generic instantiation of `main` from here
/home/judge/data/code/Main.nim(2, 64) Error: cannot open file: queues

ソースコード

diff #

template main(MAIN_BODY:untyped):untyped =
  import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables
  template get():string = stdin.readLine()
  template times(n:int,body:untyped): untyped = (for _ in 0..<n: body)
  template rep(i:untyped,n:int,body:untyped):untyped =
    block:(var i = 0; while i < n:( body; i += 1))
  template each[T](arr:var seq[T],elem,body:untyped):untyped =
    for _ in 0..<arr.len:(proc (elem:var T):auto = body)(arr[_])
  template  `+=`(x,y:typed):void = x = x + y
  template  `-=`(x,y:typed):void = x = x - y
  template  `*=`(x,y:typed):void = x = x * y
  template  `/=`(x,y:typed):void = x = x / y
  template  `%=`(x,y:typed):void = x = x mod y
  template `//=`(x,y:typed):void = x = x div y
  proc popcount(n:int):cint{.importC: "__builtin_popcount", noDecl .} # sum of "1"
  proc clz(n:int):cint{.importC: "__builtin_clz", noDecl .} # <0000>10 -> 4
  proc ctz(n:int):cint{.importC: "__builtin_ctz", noDecl .} # 01<0000> -> 4
  if isMainModule:
    MAIN_BODY

main:
  let
    N = get().parseInt
    ws = get().split().map(parseInt)
    goal = ws.sum() div 2
  if ws.sum() mod 2 == 1 :
    echo "impossible"
    quit()
  var dp = newSeqWith(goal+1,newSeqWith(N,false))
  proc dfs(x,i:int):void =
    if dp[x][i]:
      return
    if x == 0 or (i == N-1 and x - ws[i] == 0):
      echo "possible"
      quit()
    if i == N - 1:
      dp[x][i] = true
      return
    if x - ws[i] >= 0:
      dfs(x - ws[i],i+1)
    dfs(x,i+1)
    dp[x][i] = true
  dfs(goal,0)
  echo "impossible"
0