結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2015-04-03 00:09:03 |
言語 | Ruby (3.4.1) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 785 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-07-01 07:18:53 |
合計ジャッジ時間 | 4,160 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 33 |
コンパイルメッセージ
Syntax OK
ソースコード
class Fixnum def bitcount self.to_s(2).chars.count('1') end end class Yukicoder UNKNOWN = -1 def initialize n = gets.chomp.to_i check_list = Hash.new(UNKNOWN) check_list[1] = 1 dist = 2 states = [1] while states.any? next_states = [] states.each do |s| move_dist = s.bitcount a = s - move_dist b = s + move_dist if a >= 1 && check_list[a] == UNKNOWN check_list[s - move_dist] = dist next_states << s - move_dist end if b <= n && check_list[b] == UNKNOWN check_list[s + move_dist] = dist next_states << s + move_dist end end states = next_states.dup dist += 1 end puts check_list[n] end end Yukicoder.new