結果

問題 No.3 ビットすごろく
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-30 12:38:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 346 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 79,284 KB
最終ジャッジ日時 2023-09-09 06:33:49
合計ジャッジ時間 5,854 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,612 KB
testcase_01 AC 93 ms
71,476 KB
testcase_02 AC 95 ms
71,496 KB
testcase_03 AC 114 ms
77,544 KB
testcase_04 AC 98 ms
76,704 KB
testcase_05 AC 111 ms
78,332 KB
testcase_06 AC 111 ms
77,852 KB
testcase_07 AC 108 ms
77,632 KB
testcase_08 AC 112 ms
78,400 KB
testcase_09 AC 118 ms
78,608 KB
testcase_10 AC 115 ms
79,060 KB
testcase_11 AC 112 ms
78,496 KB
testcase_12 AC 113 ms
78,412 KB
testcase_13 AC 110 ms
77,728 KB
testcase_14 AC 114 ms
79,024 KB
testcase_15 AC 120 ms
79,012 KB
testcase_16 AC 117 ms
79,056 KB
testcase_17 AC 117 ms
78,848 KB
testcase_18 AC 109 ms
77,604 KB
testcase_19 AC 118 ms
79,248 KB
testcase_20 AC 95 ms
71,328 KB
testcase_21 AC 94 ms
71,748 KB
testcase_22 AC 117 ms
79,284 KB
testcase_23 AC 117 ms
79,012 KB
testcase_24 AC 116 ms
79,104 KB
testcase_25 AC 118 ms
79,000 KB
testcase_26 AC 94 ms
71,440 KB
testcase_27 AC 111 ms
77,580 KB
testcase_28 AC 116 ms
79,152 KB
testcase_29 AC 111 ms
78,224 KB
testcase_30 AC 94 ms
71,580 KB
testcase_31 AC 92 ms
71,460 KB
testcase_32 AC 113 ms
78,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
g=[[] for _ in range(n+1)]
for i in range(1,n):
  m=bin(i).count("1")
  if i+m<=n:g[i].append(i+m)
  if 1<=i-m:g[i].append(i-m)
from collections import deque
seen=[-1]*(n+1)
seen[1]=1
todo=deque([1])
while todo:
  v=todo.popleft()
  for nv in g[v]:
    if seen[nv]==-1:
      seen[nv]=seen[v]+1
      todo.append(nv)
print(seen[n])
0