結果

問題 No.3 ビットすごろく
ユーザー togatogatogatoga
提出日時 2015-08-15 07:29:14
言語 Python2
(2.7.18)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 6,492 KB
実行使用メモリ 7,344 KB
最終ジャッジ日時 2023-09-13 23:18:54
合計ジャッジ時間 3,743 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,632 KB
testcase_01 AC 14 ms
6,632 KB
testcase_02 AC 14 ms
6,608 KB
testcase_03 AC 34 ms
6,668 KB
testcase_04 AC 20 ms
6,668 KB
testcase_05 AC 55 ms
6,704 KB
testcase_06 AC 35 ms
6,816 KB
testcase_07 AC 26 ms
6,816 KB
testcase_08 AC 46 ms
6,760 KB
testcase_09 AC 67 ms
6,804 KB
testcase_10 AC 77 ms
7,188 KB
testcase_11 AC 62 ms
6,928 KB
testcase_12 AC 54 ms
6,848 KB
testcase_13 AC 31 ms
6,764 KB
testcase_14 AC 75 ms
7,204 KB
testcase_15 AC 91 ms
7,340 KB
testcase_16 AC 84 ms
7,292 KB
testcase_17 AC 92 ms
7,332 KB
testcase_18 AC 29 ms
6,672 KB
testcase_19 AC 93 ms
7,344 KB
testcase_20 AC 18 ms
6,648 KB
testcase_21 AC 14 ms
6,764 KB
testcase_22 AC 77 ms
7,344 KB
testcase_23 AC 89 ms
7,188 KB
testcase_24 AC 89 ms
7,180 KB
testcase_25 AC 91 ms
7,192 KB
testcase_26 AC 14 ms
6,752 KB
testcase_27 AC 31 ms
6,684 KB
testcase_28 AC 84 ms
7,324 KB
testcase_29 AC 63 ms
6,740 KB
testcase_30 AC 16 ms
6,704 KB
testcase_31 AC 16 ms
6,644 KB
testcase_32 AC 59 ms
6,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from Queue import Queue
import sys
N = input()
q  = Queue()
q.put([1, 0])
visit = set()
while (q.empty() == False):
    pos = q.get()
    if (pos[0] <= 0 or pos[0] >= N + 1):
        continue
    if (pos[0] == N):
        print pos[1] + 1
        sys.exit(0)
    if (pos[0] in visit):
        continue
    visit.add(pos[0])
    x = bin(pos[0]).count("1")
    q.put([pos[0] + x, pos[1] + 1])
    q.put([pos[0] - x, pos[1] + 1])
print -1
0