結果

問題 No.3 ビットすごろく
ユーザー syunsuke1024syunsuke1024
提出日時 2020-05-06 10:39:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 76,680 KB
最終ジャッジ日時 2023-09-14 01:43:28
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,008 KB
testcase_01 AC 75 ms
71,188 KB
testcase_02 AC 74 ms
71,360 KB
testcase_03 AC 88 ms
76,428 KB
testcase_04 AC 77 ms
71,184 KB
testcase_05 AC 96 ms
76,680 KB
testcase_06 AC 87 ms
76,264 KB
testcase_07 AC 84 ms
76,444 KB
testcase_08 AC 92 ms
76,288 KB
testcase_09 AC 93 ms
76,336 KB
testcase_10 AC 95 ms
76,464 KB
testcase_11 AC 93 ms
76,396 KB
testcase_12 AC 93 ms
76,404 KB
testcase_13 AC 85 ms
76,292 KB
testcase_14 AC 95 ms
76,492 KB
testcase_15 AC 95 ms
76,124 KB
testcase_16 AC 95 ms
76,496 KB
testcase_17 AC 94 ms
76,416 KB
testcase_18 AC 85 ms
76,436 KB
testcase_19 AC 97 ms
76,348 KB
testcase_20 AC 76 ms
71,244 KB
testcase_21 AC 73 ms
71,180 KB
testcase_22 AC 94 ms
76,460 KB
testcase_23 AC 94 ms
76,408 KB
testcase_24 AC 94 ms
76,472 KB
testcase_25 AC 92 ms
76,532 KB
testcase_26 AC 74 ms
71,048 KB
testcase_27 AC 85 ms
76,232 KB
testcase_28 AC 96 ms
76,328 KB
testcase_29 AC 93 ms
76,372 KB
testcase_30 AC 75 ms
71,348 KB
testcase_31 AC 73 ms
71,188 KB
testcase_32 AC 93 ms
76,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
D=[10**9 for i in range(N+1)]
D[0]=0
D[1]=1

Q=[1]
for i in range(10**6):
    if i==len(Q):
        break
    n=Q[i]
    sn=str(bin(Q[i]))
    cnt=sn.count("1")
    #print(cnt)
    if Q[i]+cnt<=N and D[Q[i]+cnt]==10**9:
        D[Q[i]+cnt]=D[Q[i]]+1
        Q.append(Q[i]+cnt)
    if Q[i]-cnt>1 and D[Q[i]-cnt]==10**9:
        D[Q[i]-cnt]=D[Q[i]]+1
        Q.append(Q[i]-cnt)
if D[N]==10**9:
    print(-1)
else:
    print(D[N])
0