結果

問題 No.4 おもりと天秤
ユーザー te-shte-sh
提出日時 2020-01-14 15:46:07
言語 Nim
(2.0.2)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 464 bytes
コンパイル時間 4,099 ms
コンパイル使用メモリ 68,172 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 18:06:10
合計ジャッジ時間 5,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 6 ms
4,384 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# URL: https://yukicoder.me/problems/no/4

import math, sequtils, strutils

var
  n = stdin.readline.parseInt
  w = stdin.readline.split.map(parseInt)
  ws = w.sum

if ws mod 2 == 1:
  echo "impossible"
  quit 0
ws = ws div 2

var dp = newSeqWith(n+1, newSeq[bool](ws+1))
dp[0][0] = true

for i in 0..<n:
  for j in 0..ws:
    dp[i+1][j] = dp[i][j]
    if j >= w[i]:
      dp[i+1][j] = dp[i+1][j] or dp[i][j-w[i]]

echo if dp[n][ws]: "possible" else: "impossible"
0