結果

問題 No.3 ビットすごろく
ユーザー takakintakakin
提出日時 2020-03-29 09:09:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 8,616 KB
最終ジャッジ日時 2023-08-30 18:38:30
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,760 KB
testcase_01 AC 16 ms
7,764 KB
testcase_02 AC 17 ms
7,764 KB
testcase_03 AC 19 ms
7,828 KB
testcase_04 WA -
testcase_05 AC 23 ms
8,276 KB
testcase_06 AC 20 ms
7,928 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 23 ms
8,464 KB
testcase_13 AC 19 ms
7,832 KB
testcase_14 AC 27 ms
8,464 KB
testcase_15 AC 29 ms
8,352 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 16 ms
7,764 KB
testcase_22 AC 28 ms
8,472 KB
testcase_23 AC 30 ms
8,188 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
7,756 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
inf=float("inf")
Dist=[inf]*(n+1)

def popcount(x):
  x=x-((x>>1)&0x5555555555555555)
  x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333)

  x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f
  x=x+(x>>8)
  x=x+(x>>16)
  x=x+(x>>32)
  return x&0x0000007f

S=[1]
Dist[1]=1
while S:
  s=S.pop()
  ss=popcount(s)
  if s+ss<=n and Dist[s+ss]==inf:
    Dist[s+ss]=Dist[s]+1
    S.append(s+ss)
  if s-ss>=1 and Dist[s-ss]==inf:
    S.append(s-ss)
    Dist[s-ss]=Dist[s]+1
print(-1 if Dist[n]==inf else Dist[n])
0