結果

問題 No.3 ビットすごろく
ユーザー Shintani Teppei
提出日時 2017-10-31 16:12:42
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 332 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-11-22 10:46:41
合計ジャッジ時間 4,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:12: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

n = gets.to_i
arr = (1..n).to_a.map { |i| i.digits(2).count(1) }
check = [false] * n
pos = 0
cnt = 1

while pos + 1 != n
    # p pos
    # p check
    
    if check[pos]
        puts -1
        exit 0
    end
    
    check[pos] = true
    pos = pos+1 + arr[pos] > n ? pos - arr[pos] : pos + arr[pos]
    cnt += 1
    
end

puts cnt
0