結果

問題 No.3 ビットすごろく
ユーザー takumijintakumijin
提出日時 2019-10-11 12:16:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 753 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2023-09-14 01:29:09
合計ジャッジ時間 2,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,852 KB
testcase_01 AC 16 ms
7,928 KB
testcase_02 AC 16 ms
7,824 KB
testcase_03 AC 23 ms
8,188 KB
testcase_04 AC 16 ms
7,840 KB
testcase_05 AC 29 ms
8,296 KB
testcase_06 AC 21 ms
8,332 KB
testcase_07 AC 18 ms
8,176 KB
testcase_08 AC 26 ms
8,276 KB
testcase_09 AC 33 ms
8,248 KB
testcase_10 AC 36 ms
8,400 KB
testcase_11 AC 31 ms
8,296 KB
testcase_12 AC 28 ms
8,248 KB
testcase_13 AC 20 ms
8,176 KB
testcase_14 AC 34 ms
8,316 KB
testcase_15 AC 39 ms
8,316 KB
testcase_16 AC 39 ms
8,268 KB
testcase_17 AC 39 ms
8,320 KB
testcase_18 AC 19 ms
8,252 KB
testcase_19 AC 40 ms
8,268 KB
testcase_20 AC 16 ms
7,912 KB
testcase_21 AC 15 ms
8,144 KB
testcase_22 AC 35 ms
8,384 KB
testcase_23 AC 39 ms
8,400 KB
testcase_24 AC 41 ms
8,408 KB
testcase_25 AC 41 ms
8,408 KB
testcase_26 AC 15 ms
8,192 KB
testcase_27 AC 20 ms
8,228 KB
testcase_28 AC 40 ms
8,320 KB
testcase_29 AC 31 ms
8,420 KB
testcase_30 AC 16 ms
7,848 KB
testcase_31 AC 16 ms
7,764 KB
testcase_32 AC 30 ms
8,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder 
#ビットスゴロク
import sys
n=int(input())
if n==1:
    print(1)
    sys.exit()
if n==2:
    print(2)
    sys.exit()
data=[0]*(n+1)
data[2]=1
flag=[0]*(n+1)
flag[1]=1
flag[2]=1
que=[[2]]
count=2
while que:
    h=que.pop()
    H=[]
    for u in h:
        data[u]=count
        cnt=0
        for i in range(14):
            if (u>>i)&1==1:
                cnt+=1
        if u+cnt==n:
            print(count+1)
            break
        if u+cnt<n:
            if flag[u+cnt]==0:
                H.append(u+cnt)
                flag[u+cnt]=1
        if flag[u-cnt]==0:
            H.append(u-cnt)
            flag[u-cnt]=1
    else:
        if H:
            que.append(H)
        count+=1
        continue
    break
else:
    print(-1)
0