結果

問題 No.4 おもりと天秤
ユーザー tshigitshigi
提出日時 2016-08-01 14:44:53
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 696 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2024-04-24 13:29:53
合計ジャッジ時間 8,812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
37,632 KB
testcase_01 AC 88 ms
12,032 KB
testcase_02 AC 137 ms
12,928 KB
testcase_03 AC 78 ms
12,160 KB
testcase_04 AC 77 ms
12,032 KB
testcase_05 AC 1,463 ms
25,472 KB
testcase_06 AC 79 ms
12,032 KB
testcase_07 AC 85 ms
12,544 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

inputs = STDIN.readlines.map(&:chomp)
N = inputs[0].to_i
Ws = inputs[1].split(/\s+/).map(&:to_i)

class Omori
  def initialize(weight)
    @weight = weight
  end

  attr_reader :weight
end

def check(k, omoris)
  do_next = false
  omoris.combination(k) do |os1|
    sum1 = os1.map(&:weight).inject(:+)
    sum2 = (omoris - os1).map(&:weight).inject(:+)
    do_next = true if sum1 > sum2
    return [true, false] if sum1 == sum2
  end
  [false, do_next]
end

def main(omoris)
  n = omoris.size / 2
  n.step(1, -1) do |k|
    result, do_next = check(k, omoris)
    return true if result
    break unless do_next
  end
  false
end

puts main(Ws.map { |w| Omori.new(w) }) ? 'possible' : 'impossible'
0