結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2022-12-05 11:10:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 39 ms / 5,000 ms |
コード長 | 544 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-10-12 09:06:57 |
合計ジャッジ時間 | 2,419 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
N = int(input())import mathfrom collections import dequedef bfs(N):l=[0]*(N+1)l[1]=1q=deque()q.append(1)while(q):u=q.popleft()if u==N:return l[u]bit1_count = '{:b}'.format(u).count('1')val1 = u-bit1_countval2 = u+bit1_countif (0<val1<N+1) and (l[val1]==0):q.append(val1)l[val1] = l[u]+1if (0<val2<N+1) and (l[val2]==0):q.append(val2)l[val2] = l[u]+1return -1print(bfs(N))