結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2020-03-26 21:27:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 955 ms / 5,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-07-01 09:43:53 |
合計ジャッジ時間 | 13,559 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
def can_go(n): return sum(map(int,list(n))) N=int(input()) m=dict(zip(range(1,N+1),list(map(format,range(1,N+1),N*"b")))) queue=[1] Visited=[]#訪問済み cost=[float("inf") for i in range(N)] cost[0]=1 next_target=[] goal=N ##print(m,goal) while(1): if len(queue)==0: break target=queue[0] if target==goal: break next_target=[target+can_go(m[target]),target-can_go(m[target])] for i in next_target: if 1<=i and i<=N and not i in queue and not i in Visited: queue.append(i) cost[i-1]=cost[target-1]+1 queue.pop(0) Visited.append(target) ## print(queue,cost) if cost[-1]!=float("inf"): print(cost[N-1]) else : print(-1)