結果

問題 No.1701 half price
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2021-10-19 21:10:17
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 387 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 16,212 KB
最終ジャッジ日時 2023-10-20 10:50:55
合計ジャッジ時間 10,313 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,084 KB
testcase_01 AC 88 ms
16,084 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 90 ms
16,184 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 87 ms
16,084 KB
testcase_10 AC 84 ms
16,084 KB
testcase_11 WA -
testcase_12 AC 87 ms
16,084 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 88 ms
16,084 KB
testcase_16 AC 87 ms
16,084 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 88 ms
16,084 KB
testcase_21 AC 1,612 ms
16,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

0.upto(3**N) do |n|
  bit_str = n.to_s(3).rjust(N, '0')
  next if bit_str.count('2') > 1

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

    acc + price
  }

  answer += 1 if sum == W
end

puts answer
0