結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2015-06-11 17:00:31 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,034 ms / 5,000 ms |
コード長 | 586 bytes |
コンパイル時間 | 77 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-07-01 07:24:51 |
合計ジャッジ時間 | 14,321 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
N = int(input()) B = [] counter = [] routes = [[1]] visited = [1] turns = -1 for x in range(0, N) : B.append(bin(x+1)) counter.append(B[x].count('1')) while routes : grid = routes.pop(0) grid_a = grid[:] grid_b = grid[:] present = grid[-1] s1 = present + counter[present-1] s2 = present - counter[present-1] if present == N : turns = len(grid) if s1 not in visited and 0 < s1 <= N : visited.append(s1) grid_a.append(s1) routes.append(grid_a) if s2 not in visited and 0 < s2 <= N : visited.append(s2) grid_b.append(s2) routes.append(grid_b) print(turns)