結果

問題 No.332 数列をプレゼントに
ユーザー code-devocode-devo
提出日時 2016-01-19 10:23:40
言語 Ruby
(3.3.0)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,456 KB
実行使用メモリ 101,344 KB
最終ジャッジ日時 2023-08-25 21:45:53
合計ジャッジ時間 7,763 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,152 KB
testcase_01 AC 79 ms
15,240 KB
testcase_02 AC 71 ms
15,288 KB
testcase_03 AC 74 ms
15,196 KB
testcase_04 AC 71 ms
15,332 KB
testcase_05 AC 77 ms
15,068 KB
testcase_06 AC 217 ms
76,612 KB
testcase_07 AC 283 ms
101,344 KB
testcase_08 AC 75 ms
15,692 KB
testcase_09 AC 76 ms
15,308 KB
testcase_10 AC 80 ms
15,120 KB
testcase_11 AC 78 ms
15,588 KB
testcase_12 AC 74 ms
17,404 KB
testcase_13 AC 102 ms
30,732 KB
testcase_14 AC 72 ms
15,136 KB
testcase_15 AC 85 ms
20,108 KB
testcase_16 AC 76 ms
15,604 KB
testcase_17 AC 73 ms
15,400 KB
testcase_18 AC 81 ms
17,040 KB
testcase_19 AC 79 ms
15,480 KB
testcase_20 AC 77 ms
15,288 KB
testcase_21 AC 84 ms
19,316 KB
testcase_22 AC 79 ms
16,116 KB
testcase_23 AC 283 ms
95,808 KB
testcase_24 AC 294 ms
95,992 KB
testcase_25 AC 83 ms
15,496 KB
testcase_26 AC 308 ms
95,584 KB
testcase_27 AC 76 ms
15,176 KB
testcase_28 AC 75 ms
15,308 KB
testcase_29 AC 297 ms
96,996 KB
testcase_30 AC 293 ms
97,012 KB
testcase_31 AC 79 ms
15,312 KB
testcase_32 AC 303 ms
97,012 KB
testcase_33 AC 80 ms
16,108 KB
testcase_34 AC 89 ms
18,668 KB
testcase_35 AC 88 ms
19,796 KB
testcase_36 AC 80 ms
15,240 KB
testcase_37 AC 84 ms
16,088 KB
testcase_38 AC 84 ms
15,952 KB
testcase_39 AC 80 ms
15,980 KB
testcase_40 AC 79 ms
15,164 KB
testcase_41 AC 79 ms
15,296 KB
testcase_42 AC 79 ms
15,036 KB
testcase_43 AC 84 ms
15,676 KB
testcase_44 AC 81 ms
15,636 KB
testcase_45 AC 94 ms
23,556 KB
testcase_46 AC 93 ms
22,136 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 >= 50_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