結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-01 14:44:53 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 696 bytes |
| コンパイル時間 | 47 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 32,288 KB |
| 最終ジャッジ日時 | 2024-11-06 21:39:51 |
| 合計ジャッジ時間 | 9,075 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 14 |
コンパイルメッセージ
Syntax OK
ソースコード
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'