結果

問題 No.4 おもりと天秤
ユーザー tshigitshigi
提出日時 2016-08-01 14:44:53
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 696 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 28,844 KB
最終ジャッジ日時 2023-08-06 18:43:38
合計ジャッジ時間 9,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,128 KB
testcase_01 AC 77 ms
15,176 KB
testcase_02 AC 142 ms
17,112 KB
testcase_03 AC 83 ms
15,056 KB
testcase_04 AC 82 ms
15,308 KB
testcase_05 AC 1,520 ms
23,980 KB
testcase_06 AC 84 ms
15,168 KB
testcase_07 AC 88 ms
15,740 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