結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-08-12 08:39:23 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 563 bytes |
コンパイル時間 | 440 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-09-23 06:50:13 |
合計ジャッジ時間 | 2,447 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
import Queue n = int(input()) def chkdigit(n): count = 0 if n == 0: return 0 while n: if n%2 == 1: count += 1 n /= 2 return count q = Queue.Queue() q.put([1,0]) isvisited = [0 for i in range(n)] while not q.empty() : tmp = q.get() if tmp[0] == n: print tmp[1] + 1 quit() a = chkdigit(tmp[0]) if 0 < tmp[0] + a < n+1 and isvisited[tmp[0]-1] == 0 : isvisited[tmp[0]-1] = 1 q.put([tmp[0] + a, tmp[1] + 1]) if 0 < tmp[0] -a < n+1 and isvisited[tmp[0]-1] == 0: isvisited[tmp[0]-1] = 1 q.put([tmp[0] - a, tmp[1] + 1]) print -1