結果
問題 | No.3 ビットすごろく |
ユーザー | Hydru |
提出日時 | 2023-01-15 13:24:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 604 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 87,052 KB |
実行使用メモリ | 78,728 KB |
最終ジャッジ日時 | 2023-08-27 21:00:20 |
合計ジャッジ時間 | 6,257 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
71,640 KB |
testcase_01 | AC | 99 ms
71,600 KB |
testcase_02 | AC | 99 ms
71,588 KB |
testcase_03 | AC | 119 ms
77,736 KB |
testcase_04 | AC | 105 ms
76,920 KB |
testcase_05 | AC | 126 ms
77,808 KB |
testcase_06 | AC | 118 ms
77,732 KB |
testcase_07 | AC | 113 ms
77,608 KB |
testcase_08 | AC | 122 ms
77,612 KB |
testcase_09 | AC | 131 ms
78,412 KB |
testcase_10 | AC | 132 ms
78,460 KB |
testcase_11 | AC | 129 ms
78,528 KB |
testcase_12 | AC | 129 ms
77,956 KB |
testcase_13 | AC | 115 ms
77,628 KB |
testcase_14 | AC | 134 ms
78,424 KB |
testcase_15 | AC | 133 ms
78,728 KB |
testcase_16 | AC | 131 ms
78,452 KB |
testcase_17 | AC | 135 ms
78,580 KB |
testcase_18 | AC | 114 ms
77,784 KB |
testcase_19 | AC | 133 ms
78,480 KB |
testcase_20 | AC | 109 ms
76,304 KB |
testcase_21 | AC | 99 ms
71,828 KB |
testcase_22 | AC | 136 ms
78,324 KB |
testcase_23 | AC | 136 ms
78,592 KB |
testcase_24 | AC | 135 ms
78,436 KB |
testcase_25 | AC | 140 ms
78,612 KB |
testcase_26 | WA | - |
testcase_27 | AC | 119 ms
77,960 KB |
testcase_28 | AC | 135 ms
78,408 KB |
testcase_29 | AC | 132 ms
78,408 KB |
testcase_30 | AC | 101 ms
71,576 KB |
testcase_31 | AC | 100 ms
71,916 KB |
testcase_32 | AC | 131 ms
77,864 KB |
ソースコード
from collections import deque n=int(input()) if n==1: print(0) exit() def bit_cnt(n): result=0 while(n!=0): if n%2==1: result+=1 n//=2 return result inf=float("inf") dist=[inf for _ in range(n)] dist[0]=1 Q=deque() Q.append(0) while(Q): a=Q.popleft() x=bit_cnt(a+1) if 0<=a+x<n: if dist[a+x]>dist[a]+1: dist[a+x]=dist[a]+1 Q.append(a+x) if 0<=a-x<n: if dist[a-x]>dist[a]+1: dist[a-x]=dist[a]+1 Q.append(a-x) ans=dist[n-1] if ans==inf: print(-1) else: print(ans)