結果

問題 No.3 ビットすごろく
ユーザー 小指が強い人小指が強い人
提出日時 2015-12-06 12:32:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 594 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 11,532 KB
実行使用メモリ 15,852 KB
最終ジャッジ日時 2023-10-12 16:39:44
合計ジャッジ時間 5,579 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,088 KB
testcase_01 AC 84 ms
15,032 KB
testcase_02 AC 84 ms
15,036 KB
testcase_03 AC 94 ms
15,184 KB
testcase_04 AC 88 ms
15,200 KB
testcase_05 AC 106 ms
15,336 KB
testcase_06 AC 94 ms
15,244 KB
testcase_07 AC 90 ms
15,268 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 105 ms
15,324 KB
testcase_13 AC 92 ms
15,228 KB
testcase_14 AC 116 ms
15,548 KB
testcase_15 AC 123 ms
15,652 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 92 ms
15,236 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 85 ms
15,036 KB
testcase_22 AC 116 ms
15,400 KB
testcase_23 AC 123 ms
15,696 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 84 ms
15,044 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 87 ms
15,084 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

def process(count, ni)
    if ni == $n
        $min = count if count < $min
        return
    end
    $b[ni] = true
    front = ni + $bit[ni]
    back = ni - $bit[ni]
    if front <= $n && !$b[front]
        process(count + 1, front)
    end
    if back > 0 && !$b[back]
        process(count + 1, back)
    end
    return
end
$n = gets.to_i
$b = Array.new($n + 1, false)
$bit = Array.new($n + 1, 0)
$min = 99999999
($n + 1).times do |i| 
    s = i.to_s(2)
    s.each_char do |c|
        $bit[i] += 1 if c == "1"
    end
end
process(1, 1)
if $min < 99999999
    puts $min
else
    puts -1
end
0