結果

問題 No.3 ビットすごろく
ユーザー finefine
提出日時 2016-03-22 00:47:12
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 476 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-08 21:37:08
合計ジャッジ時間 5,045 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
16,256 KB
testcase_01 AC 89 ms
16,256 KB
testcase_02 AC 89 ms
16,256 KB
testcase_03 AC 88 ms
16,256 KB
testcase_04 WA -
testcase_05 AC 93 ms
16,384 KB
testcase_06 AC 97 ms
16,256 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 94 ms
16,384 KB
testcase_13 AC 93 ms
16,256 KB
testcase_14 AC 96 ms
16,384 KB
testcase_15 AC 101 ms
16,384 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 92 ms
16,256 KB
testcase_22 AC 101 ms
16,384 KB
testcase_23 AC 105 ms
16,384 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 95 ms
16,256 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

n = gets.to_i
ans = Array.new(n,-1)
a = [[1,1]]
min = 100000
until a.empty?
    x = a.pop
    if x[0] == n
        min = [min, x[1]].min
    elsif ans[x[0] - 1] != -1
        next
    else
        ans[x[0] - 1] = x[1]
        tmp = x[0].to_s(2).count('1')
        if x[0] + tmp <= n
            a.push([x[0] + tmp, x[1] + 1])
        end
        if x[0] - tmp > 0
            a.push([x[0] - tmp, x[1] + 1])
        end
    end
end

if min == 100000
    p -1
else
    p min
end
0