結果
問題 | No.3 ビットすごろく |
ユーザー | 双六 |
提出日時 | 2020-07-22 09:20:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 124 ms / 5,000 ms |
コード長 | 1,104 bytes |
コンパイル時間 | 290 ms |
コンパイル使用メモリ | 86,992 KB |
実行使用メモリ | 78,276 KB |
最終ジャッジ日時 | 2023-09-14 01:48:31 |
合計ジャッジ時間 | 5,309 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
71,640 KB |
testcase_01 | AC | 97 ms
71,312 KB |
testcase_02 | AC | 100 ms
71,748 KB |
testcase_03 | AC | 124 ms
77,656 KB |
testcase_04 | AC | 110 ms
77,380 KB |
testcase_05 | AC | 113 ms
77,992 KB |
testcase_06 | AC | 112 ms
77,684 KB |
testcase_07 | AC | 110 ms
77,600 KB |
testcase_08 | AC | 114 ms
77,708 KB |
testcase_09 | AC | 115 ms
77,752 KB |
testcase_10 | AC | 115 ms
78,140 KB |
testcase_11 | AC | 115 ms
77,668 KB |
testcase_12 | AC | 112 ms
77,740 KB |
testcase_13 | AC | 112 ms
77,684 KB |
testcase_14 | AC | 116 ms
77,844 KB |
testcase_15 | AC | 116 ms
78,200 KB |
testcase_16 | AC | 114 ms
78,088 KB |
testcase_17 | AC | 117 ms
78,124 KB |
testcase_18 | AC | 112 ms
77,612 KB |
testcase_19 | AC | 115 ms
78,276 KB |
testcase_20 | AC | 103 ms
76,220 KB |
testcase_21 | AC | 94 ms
71,508 KB |
testcase_22 | AC | 114 ms
77,868 KB |
testcase_23 | AC | 115 ms
78,076 KB |
testcase_24 | AC | 114 ms
78,208 KB |
testcase_25 | AC | 116 ms
78,076 KB |
testcase_26 | AC | 96 ms
71,352 KB |
testcase_27 | AC | 110 ms
77,620 KB |
testcase_28 | AC | 113 ms
78,264 KB |
testcase_29 | AC | 112 ms
77,752 KB |
testcase_30 | AC | 95 ms
71,808 KB |
testcase_31 | AC | 97 ms
71,464 KB |
testcase_32 | AC | 111 ms
77,772 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict from collections import deque INF = float("inf") def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) class BFS(object): def __init__(self, graph, s, N): self.g = graph.graph self.Q = deque(); self.Q.append(s) self.dist = [INF] * N; self.dist[s] = 0 while self.Q: v = self.Q.popleft() for i in self.g[v]: if self.dist[i] == INF: self.dist[i] = self.dist[v] + 1 self.Q.append(i) #処理内容 def main(): N = int(input()) G = Graph() for i in range(1, N + 1): n = i cnt = 0 while True: if n % 2 == 1: cnt += 1 n >>= 1 if n == 0: break if i - cnt >= 1: G.add_edge(i, i - cnt) G.add_edge(i, i + cnt) BF = BFS(G, 1, N + 100) # print(BF.dist) ans = BF.dist[N] if ans == INF: print(-1) else: print(ans + 1) if __name__ == '__main__': main()