結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2017-10-31 16:44:40 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 381 bytes |
コンパイル時間 | 47 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-11-22 10:47:33 |
合計ジャッジ時間 | 4,751 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 33 |
コンパイルメッセージ
Main.rb:20: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
n = gets.to_i arr = (1..n).to_a.map { |i| i.digits(2).count(1) } INF = 10000000 dp = [INF] * n dp[0] = 1 p arr arr.each_with_index do |num, i| # p dp, num, i if i + num <= n-1 dp[i+num] = [dp[i+num], dp[i] + 1].min end if i - num >= 0 dp[i-num] = [dp[i-num], dp[i] + 1].min end end if dp[n-1] == INF puts -1 return end puts dp[n-1]