結果
| 問題 | 
                            No.1701 half price
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-10-19 21:10:17 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 387 bytes | 
| コンパイル時間 | 337 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-09-20 06:25:38 | 
| 合計ジャッジ時間 | 8,859 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 8 WA * 12 | 
コンパイルメッセージ
Syntax OK
ソースコード
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