結果

問題 No.332 数列をプレゼントに
ユーザー code-devocode-devo
提出日時 2016-01-19 10:07:12
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 901 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 145,004 KB
最終ジャッジ日時 2023-10-21 06:50:41
合計ジャッジ時間 11,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
16,048 KB
testcase_01 AC 87 ms
16,052 KB
testcase_02 AC 88 ms
16,052 KB
testcase_03 AC 87 ms
16,052 KB
testcase_04 AC 87 ms
16,052 KB
testcase_05 AC 93 ms
16,052 KB
testcase_06 AC 332 ms
101,896 KB
testcase_07 AC 442 ms
133,204 KB
testcase_08 AC 90 ms
16,576 KB
testcase_09 AC 88 ms
16,052 KB
testcase_10 AC 90 ms
16,052 KB
testcase_11 AC 90 ms
16,360 KB
testcase_12 AC 93 ms
18,196 KB
testcase_13 AC 122 ms
31,536 KB
testcase_14 AC 91 ms
16,052 KB
testcase_15 AC 102 ms
21,064 KB
testcase_16 AC 90 ms
16,340 KB
testcase_17 AC 90 ms
16,312 KB
testcase_18 AC 103 ms
17,924 KB
testcase_19 AC 89 ms
16,312 KB
testcase_20 AC 94 ms
16,312 KB
testcase_21 AC 103 ms
20,272 KB
testcase_22 AC 93 ms
16,840 KB
testcase_23 WA -
testcase_24 AC 518 ms
143,348 KB
testcase_25 AC 89 ms
16,312 KB
testcase_26 WA -
testcase_27 AC 90 ms
16,052 KB
testcase_28 AC 88 ms
16,052 KB
testcase_29 AC 518 ms
144,976 KB
testcase_30 WA -
testcase_31 AC 88 ms
16,064 KB
testcase_32 AC 504 ms
144,976 KB
testcase_33 AC 91 ms
17,104 KB
testcase_34 AC 96 ms
19,480 KB
testcase_35 AC 97 ms
20,536 KB
testcase_36 AC 87 ms
16,052 KB
testcase_37 AC 92 ms
16,872 KB
testcase_38 AC 90 ms
16,868 KB
testcase_39 AC 93 ms
16,868 KB
testcase_40 AC 89 ms
16,052 KB
testcase_41 AC 86 ms
16,052 KB
testcase_42 AC 86 ms
16,052 KB
testcase_43 AC 92 ms
16,604 KB
testcase_44 AC 89 ms
16,840 KB
testcase_45 AC 102 ms
24,420 KB
testcase_46 AC 103 ms
22,864 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, idxs|
    new_sum = sum + num
    print_ans(hash1[X - new_sum] + idxs) if hash1[X - new_sum]
    add[new_sum] = idxs.dup << idx if new_sum < X && !hash2[new_sum]
  end
  hash2.update(add)
end

puts "No"
0