結果

問題 No.1701 half price
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2021-10-19 21:46:31
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 448 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 20,748 KB
最終ジャッジ日時 2023-10-20 10:51:07
合計ジャッジ時間 7,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
20,656 KB
testcase_01 AC 90 ms
16,308 KB
testcase_02 AC 1,203 ms
16,400 KB
testcase_03 AC 90 ms
16,308 KB
testcase_04 AC 1,193 ms
16,400 KB
testcase_05 AC 99 ms
16,400 KB
testcase_06 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'set'

N, W = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
answer = Set.new

(3**N).times do |n|
  bit_str = n.to_s(3).rjust(N, '0')
  key = 0

  sum = bit_str.chars.each_with_index.inject(0) { |acc, (bit, i)|
    price = case bit
    when '0'
      0
    when '1'
      key += (1 << i)
      a[i]
    else
      key += (1 << i)
      a[i] / 2
    end

    acc + price
  }

  next unless sum == W

  answer << key
end

puts answer.size
0