結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-12 08:53:41 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 623 bytes |
| コンパイル時間 | 307 ms |
| コンパイル使用メモリ | 7,068 KB |
| 実行使用メモリ | 17,956 KB |
| 最終ジャッジ日時 | 2024-09-23 06:50:28 |
| 合計ジャッジ時間 | 12,485 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 5 TLE * 1 -- * 23 |
ソースコード
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 = [-1 for i in range(n)] isvisited[0] = 0 while not q.empty() : tmp = q.get() if tmp[0] == n: print isvisited print tmp[1] + 1 quit() a = chkdigit(tmp[0]) if 0 < tmp[0] + a < n+1 and isvisited[tmp[0]-1+a] == -1 : isvisited[tmp[0]-1] = tmp[1] + 1 q.put([tmp[0] + a, tmp[1] + 1]) if 0 < tmp[0] -a < n+1 and isvisited[tmp[0]-1-a] == -1: isvisited[tmp[0]-1] = tmp[1] + 1 q.put([tmp[0] - a, tmp[1] + 1]) print -1