結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-17 16:25:36 |
| 言語 | Ruby (4.0.1) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 5,000 ms |
| コード長 | 240 bytes |
| 記録 | |
| コンパイル時間 | 448 ms |
| コンパイル使用メモリ | 8,576 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-03-22 02:56:44 |
| 合計ジャッジ時間 | 3,835 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
Main.rb:1: warning: shebang line ending with \r may cause problems Syntax OK
ソースコード
#!/usr/bin/ruby
N=gets.to_i
a=[nil]*(N+1)
a[1]=1
q=[1]
while !q.empty?
cur=q.shift
d=cur.to_s(2).count('1')
[-d,d].each{|e|
if 1<=cur+e&&cur+e<=N && !a[cur+e]
a[cur+e]=a[cur]+1
q.push(cur+e)
end
}
end
p a[N]||-1