結果

問題 No.332 数列をプレゼントに
ユーザー code-devocode-devo
提出日時 2016-01-19 10:32:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,328 KB
実行使用メモリ 33,588 KB
最終ジャッジ日時 2023-08-25 21:49:28
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,208 KB
testcase_01 AC 79 ms
15,220 KB
testcase_02 AC 78 ms
15,276 KB
testcase_03 AC 78 ms
15,128 KB
testcase_04 AC 79 ms
15,228 KB
testcase_05 AC 79 ms
15,104 KB
testcase_06 AC 107 ms
28,524 KB
testcase_07 AC 118 ms
33,588 KB
testcase_08 AC 82 ms
15,668 KB
testcase_09 AC 79 ms
15,068 KB
testcase_10 AC 79 ms
15,084 KB
testcase_11 AC 82 ms
15,380 KB
testcase_12 AC 85 ms
17,248 KB
testcase_13 AC 111 ms
30,712 KB
testcase_14 AC 79 ms
15,072 KB
testcase_15 AC 95 ms
20,096 KB
testcase_16 AC 81 ms
15,504 KB
testcase_17 AC 81 ms
15,352 KB
testcase_18 AC 87 ms
16,968 KB
testcase_19 AC 79 ms
15,248 KB
testcase_20 AC 81 ms
15,352 KB
testcase_21 AC 91 ms
19,500 KB
testcase_22 AC 83 ms
15,824 KB
testcase_23 AC 109 ms
26,824 KB
testcase_24 AC 112 ms
27,940 KB
testcase_25 AC 81 ms
15,492 KB
testcase_26 AC 110 ms
27,288 KB
testcase_27 AC 79 ms
15,064 KB
testcase_28 AC 80 ms
14,992 KB
testcase_29 AC 106 ms
26,796 KB
testcase_30 AC 107 ms
27,084 KB
testcase_31 AC 80 ms
15,296 KB
testcase_32 AC 105 ms
26,736 KB
testcase_33 AC 83 ms
16,068 KB
testcase_34 AC 87 ms
18,720 KB
testcase_35 AC 92 ms
19,716 KB
testcase_36 AC 78 ms
15,252 KB
testcase_37 AC 84 ms
15,920 KB
testcase_38 AC 84 ms
16,104 KB
testcase_39 AC 83 ms
15,808 KB
testcase_40 AC 79 ms
15,040 KB
testcase_41 AC 79 ms
15,092 KB
testcase_42 AC 80 ms
15,256 KB
testcase_43 AC 85 ms
15,608 KB
testcase_44 AC 83 ms
15,668 KB
testcase_45 AC 95 ms
23,284 KB
testcase_46 AC 96 ms
22,004 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
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 >= 10_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