結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2015-10-06 02:35:03 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 68 ms / 5,000 ms |
コード長 | 541 bytes |
コンパイル時間 | 100 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-01 07:33:55 |
合計ジャッジ時間 | 2,434 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
# coding: utf-8 from Queue import Queue INF = 1e9+7 N = int(raw_input()) def bc(x): return bin(x).count("1") to_list = [] for i in range(1, N+1): bci=bc(i) temp_to = [] if i-bci > 0: temp_to.append(i-bci-1) if i+bci < N+1: temp_to.append(i+bci-1) to_list.append(temp_to) #bfsをするよ! chk = [INF for _ in range(N)] chk[0] = 1 que = Queue() que.put(0) while not que.empty(): q = que.get() for i in to_list[q]: if chk[i] == INF: chk[i]=chk[q]+1 que.put(i) if chk[N-1] == INF: print '-1' else: print chk[N-1]