結果
問題 | No.4 おもりと天秤 |
ユーザー | nishima |
提出日時 | 2015-11-07 13:00:16 |
言語 | Ruby (3.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 525 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 11,336 KB |
実行使用メモリ | 16,132 KB |
最終ジャッジ日時 | 2023-10-11 14:58:23 |
合計ジャッジ時間 | 7,659 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
15,252 KB |
testcase_01 | AC | 78 ms
15,256 KB |
testcase_02 | AC | 91 ms
16,132 KB |
testcase_03 | AC | 78 ms
15,272 KB |
testcase_04 | AC | 78 ms
15,236 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
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
ソースコード
# http://yukicoder.me/problems/19 n = $stdin.gets.chomp.to_i w = $stdin.gets.chomp.split(/ /).map(&:to_i).sort dp = Array.new( n ){ Array.new() } sum = w.inject( :+ ) if sum % 2 == 1 puts "impossible" exit else sum2 = sum / 2 0.upto( n - 1 ){ |i| val = w[ i ] dp[ i ] = dp[ i - 1].dup dp[ i ] << val dp[ i - 1 ].each{ |e| dp[ i ] << ( e + val ) } dp[ i ].uniq! unless dp[ i ].uniq dp[ i ].sort! dp[ i ].each{ |e| if e == sum2 puts "possible" exit end } } puts "impossible" end