結果

問題 No.332 数列をプレゼントに
ユーザー code-devocode-devo
提出日時 2016-01-19 10:16:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 11,372 KB
実行使用メモリ 144,084 KB
最終ジャッジ日時 2023-08-25 21:45:14
合計ジャッジ時間 11,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,300 KB
testcase_01 AC 78 ms
15,272 KB
testcase_02 AC 78 ms
15,032 KB
testcase_03 AC 79 ms
15,148 KB
testcase_04 AC 80 ms
15,036 KB
testcase_05 AC 81 ms
15,192 KB
testcase_06 AC 332 ms
101,136 KB
testcase_07 AC 462 ms
132,476 KB
testcase_08 AC 81 ms
15,632 KB
testcase_09 AC 80 ms
15,312 KB
testcase_10 AC 78 ms
15,136 KB
testcase_11 AC 80 ms
15,464 KB
testcase_12 AC 83 ms
17,212 KB
testcase_13 AC 112 ms
30,740 KB
testcase_14 AC 79 ms
15,304 KB
testcase_15 AC 92 ms
20,240 KB
testcase_16 AC 82 ms
15,500 KB
testcase_17 AC 79 ms
15,508 KB
testcase_18 AC 83 ms
17,184 KB
testcase_19 AC 79 ms
15,288 KB
testcase_20 AC 81 ms
15,548 KB
testcase_21 AC 91 ms
19,416 KB
testcase_22 AC 82 ms
16,100 KB
testcase_23 AC 491 ms
142,460 KB
testcase_24 AC 496 ms
142,436 KB
testcase_25 AC 79 ms
15,456 KB
testcase_26 AC 498 ms
142,340 KB
testcase_27 AC 79 ms
15,184 KB
testcase_28 AC 79 ms
15,024 KB
testcase_29 AC 501 ms
144,084 KB
testcase_30 AC 515 ms
143,716 KB
testcase_31 AC 80 ms
15,128 KB
testcase_32 AC 516 ms
143,608 KB
testcase_33 AC 87 ms
16,244 KB
testcase_34 AC 91 ms
18,560 KB
testcase_35 AC 91 ms
19,772 KB
testcase_36 AC 79 ms
15,132 KB
testcase_37 AC 83 ms
15,940 KB
testcase_38 AC 83 ms
16,016 KB
testcase_39 AC 86 ms
15,864 KB
testcase_40 AC 81 ms
15,296 KB
testcase_41 AC 79 ms
15,092 KB
testcase_42 AC 81 ms
15,112 KB
testcase_43 AC 85 ms
15,816 KB
testcase_44 AC 83 ms
15,616 KB
testcase_45 AC 96 ms
23,428 KB
testcase_46 AC 99 ms
22,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, X = gets.split.map(&:to_i)
NS = gets.split.map(&:to_i)

def print_ans(idxs)
  puts (0...N).map{|i| idxs.include?(i) ? "o" : "x"}.join
  exit #こんなところでexitは使いたくない
end

nis = NS.map.with_index{|n,idx| [n,idx]}.select{|a| a[0] <= X}.sort

hash1 = Hash.new
hash1[0] = []
while ni = nis.shift do
  num, idx = ni
  add = {}
  hash1.each do |sum, idxs|
    new_sum = sum + num
    print_ans(idxs.dup << idx) if new_sum == X
    add[new_sum] = idxs.dup << idx if new_sum < X && !hash1[new_sum]
  end  
  hash1.update(add)
  break if hash1.size >= 100_000
end

hash2 = Hash.new
hash2[0] = []
while ni = nis.shift do
  num, idx = ni
  add = {}
  hash2.each do |sum, idxs2|
    new_sum = sum + num
    idxs1 = hash1[X - new_sum]
    print_ans((idxs1 + idxs2) << idx) if idxs1
    add[new_sum] = idxs2.dup << idx if new_sum < X && !hash2[new_sum]
  end
  hash2.update(add)
end

puts "No"
0