結果

問題 No.3 ビットすごろく
ユーザー 1up_aloe1up_aloe
提出日時 2018-01-31 21:43:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 603 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 16,276 KB
最終ジャッジ日時 2023-08-28 17:32:45
合計ジャッジ時間 6,722 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,768 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,808 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

nin = int(input())
mark = 100000
queue = []
bitlis = []

for i in range(1,nin+1):
  bit = 0
  for item in list(str(bin(i))):
    if item == "1":
      bit += 1
  bitlis.append(bit)

def dps(n,m=1,lis=[]):
  xlis = lis.copy()
  xlis.append(n)
  if n == nin:
    global mark
    mark = min(m,len(xlis))
    return
      
  for item in [n+bitlis[n-1],n-bitlis[n-1]]:
    if item < 1 or item > nin:
      continue
    else:
      if not item in xlis:
        queue.append((item,m+1,xlis))

dps(1)
while queue:
  Tp = queue.pop()
  dps(Tp[0],Tp[1],Tp[2])
  
if mark != 100000:
  print(mark)
else:
  print(-1)
0