結果

問題 No.3 ビットすごろく
ユーザー MaboyMaboy
提出日時 2017-04-17 18:32:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,779 ms / 5,000 ms
コード長 453 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 8,944 KB
最終ジャッジ日時 2023-09-14 00:42:32
合計ジャッジ時間 34,314 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,552 KB
testcase_01 AC 19 ms
8,616 KB
testcase_02 AC 18 ms
8,492 KB
testcase_03 AC 165 ms
8,580 KB
testcase_04 AC 31 ms
8,640 KB
testcase_05 AC 760 ms
8,696 KB
testcase_06 AC 202 ms
8,616 KB
testcase_07 AC 79 ms
8,564 KB
testcase_08 AC 483 ms
8,684 KB
testcase_09 AC 1,239 ms
8,844 KB
testcase_10 AC 1,857 ms
8,812 KB
testcase_11 AC 1,051 ms
8,724 KB
testcase_12 AC 717 ms
8,784 KB
testcase_13 AC 128 ms
8,524 KB
testcase_14 AC 1,704 ms
8,716 KB
testcase_15 AC 2,779 ms
8,800 KB
testcase_16 AC 2,254 ms
8,844 KB
testcase_17 AC 2,560 ms
8,864 KB
testcase_18 AC 96 ms
8,668 KB
testcase_19 AC 2,668 ms
8,820 KB
testcase_20 AC 24 ms
8,496 KB
testcase_21 AC 18 ms
8,464 KB
testcase_22 AC 1,738 ms
8,812 KB
testcase_23 AC 2,686 ms
8,852 KB
testcase_24 AC 2,729 ms
8,848 KB
testcase_25 AC 2,578 ms
8,772 KB
testcase_26 AC 16 ms
8,528 KB
testcase_27 AC 142 ms
8,688 KB
testcase_28 AC 2,162 ms
8,944 KB
testcase_29 AC 1,088 ms
8,732 KB
testcase_30 AC 19 ms
8,540 KB
testcase_31 AC 18 ms
8,436 KB
testcase_32 AC 943 ms
8,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def NX(a):
  global N,K
  K[a]=a
  r=[]
  b=bin(a).count("1")
  if 0 < a-b and not a-b in K:r.append(a-b)
  if N >= a+b and not a+b in K:r.append(a+b)
  return(r)

N=int(input())
G=-1 if N!=1 else 1
buf=deque()
buf.append([1,1])
if N==1:
  buf.clear()
K=[0]*(N+1)

while len(buf):
  c,n=buf.popleft()
  if n in K:continue
  for i in NX(n):
    if i==N:
      buf.clear()
      G=c+1
    buf.append([c+1,i])
    
print(G)

0