結果
問題 | No.3 ビットすごろく |
ユーザー | nakanolab |
提出日時 | 2015-05-31 17:13:00 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 508 bytes |
コンパイル時間 | 43 ms |
コンパイル使用メモリ | 6,516 KB |
実行使用メモリ | 7,148 KB |
最終ジャッジ日時 | 2023-09-20 18:04:41 |
合計ジャッジ時間 | 2,544 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 11 ms
6,008 KB |
testcase_03 | AC | 18 ms
6,332 KB |
testcase_04 | WA | - |
testcase_05 | AC | 34 ms
6,364 KB |
testcase_06 | AC | 21 ms
6,276 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 33 ms
6,568 KB |
testcase_13 | AC | 17 ms
6,328 KB |
testcase_14 | AC | 55 ms
6,892 KB |
testcase_15 | AC | 72 ms
7,108 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 55 ms
6,916 KB |
testcase_23 | AC | 73 ms
6,936 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 11 ms
6,032 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
ソースコード
def ones(m): return bin(m).count('1') def expand(m, n): dm = ones(m) ms = [m - dm, m + dm] return [m for m in ms if 0 < m <= n] def bfs(frontier, visited, n): while frontier: path = frontier.pop(0) last = path[-1] if last == n: return path elif last not in visited: visited.add(last) for m in expand(last, n): frontier.append(path + [m]) n = int(raw_input()) path = bfs([[1]], set(), n) if path: print '->'.join(str(i) for i in path) else: print -1