結果

問題 No.4 おもりと天秤
ユーザー DialBirdDialBird
提出日時 2017-02-11 12:05:39
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 15,388 KB
最終ジャッジ日時 2023-08-28 12:49:49
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
15,164 KB
testcase_01 AC 84 ms
15,196 KB
testcase_02 AC 83 ms
15,288 KB
testcase_03 WA -
testcase_04 AC 85 ms
15,108 KB
testcase_05 WA -
testcase_06 AC 83 ms
15,244 KB
testcase_07 WA -
testcase_08 AC 83 ms
15,372 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 84 ms
15,084 KB
testcase_12 AC 83 ms
15,048 KB
testcase_13 AC 83 ms
15,084 KB
testcase_14 AC 84 ms
15,100 KB
testcase_15 AC 83 ms
15,252 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 86 ms
15,168 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
@w_list = gets.chomp.split.map(&:to_i)
@half = 0
@dp = Array.new(100, Array.new(10001, true))

def solve(idx, total)
  return false if idx >= N || total > @half
  return @dp[idx][total] if @dp[idx][total] == false

  return true if total == @half

  return true if solve(idx + 1, total) || solve(idx + 1, total + @w_list[idx])
  return @dp[idx][total] = false
end

def main
  total = @w_list.inject(:+)

  return "impossible" if total & 1 == 1

  @half = total >> 1
  @w_list.sort!

  return solve(0, 0) ? "possible" : "impossible"
end

puts main()
0