結果

問題 No.4 おもりと天秤
ユーザー siman
提出日時 2016-03-21 22:15:01
言語 Ruby
(3.4.1)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 430 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-06-26 09:27:19
合計ジャッジ時間 3,288 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

class Yukicoder
  def initialize
    n = gets.chomp.to_i
    w = gets.chomp.split.map(&:to_i).sort
    sum = w.inject(:+)

    hash = Hash.new(false)

    w.each do |num|
      temp = hash.dup

      hash.each do |k,v|
        temp[k+num] = true
      end

      hash = temp.dup
      hash[num] = true
    end

    if sum.even? && hash[sum/2]
      puts "possible"
    else
      puts "impossible"
    end
  end
end

Yukicoder.new
0