結果

問題 No.4 おもりと天秤
ユーザー むらためむらため
提出日時 2020-06-01 08:28:23
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 598 bytes
コンパイル時間 2,750 ms
コンパイル使用メモリ 61,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 02:26:48
合計ジャッジ時間 3,786 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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