結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 86 ms
15,040 KB
testcase_03 AC 97 ms
15,228 KB
testcase_04 AC 90 ms
15,444 KB
testcase_05 AC 107 ms
15,740 KB
testcase_06 AC 96 ms
15,472 KB
testcase_07 AC 91 ms
15,384 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 107 ms
15,724 KB
testcase_13 AC 94 ms
15,428 KB
testcase_14 AC 121 ms
15,804 KB
testcase_15 AC 129 ms
15,916 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 93 ms
15,284 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 119 ms
16,084 KB
testcase_23 AC 130 ms
16,116 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 84 ms
15,288 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 86 ms
15,044 KB
testcase_31 AC 88 ms
15,352 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:39: 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
    if count >= $n / 2 || count >= $min
        return
    end
    front = ni + $bit[ni]
    back = ni - $bit[ni]
    if front <= $n && $a[ni] == 0
        $a[ni] = 1
        process(count + 1, front)
    elsif $a[ni] == 0
        $a[ni] = 1
    end
    if back > 0 && $a[ni] <= 1
        $a[ni] = 2
        process(count + 1, back)
    elsif $a[ni] <= 1
        $a[ni] = 2
    end
    return
end
$n = gets.to_i
$a = Array.new($n + 1, 0)
$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