結果

問題 No.4 おもりと天秤
ユーザー むらため
提出日時 2020-06-01 08:28:23
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 598 bytes
コンパイル時間 4,485 ms
コンパイル使用メモリ 60,340 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-21 02:12:41
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

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

let n = scan()
var W : array[101,int]
var dp : array[10001,bool]
var wSum = 0
for i in 0..<n:
  W[i] = scan()
  wSum += W[i]
if wSum mod 2 == 1 : 
  echo "impossible"
  quit 0
let m = wSum div 2
dp[0] = true
for wi in 0..<n:
  let w = W[wi]
  for i in countdown(m-w,0):
    if dp[i] : dp[i + w] = true
  if dp[m] : 
    echo "possible"
    quit 0
echo "impossible"
0