結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2020-05-06 10:39:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 60 ms / 5,000 ms |
コード長 | 442 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 71,356 KB |
最終ジャッジ日時 | 2024-07-01 09:47:30 |
合計ジャッジ時間 | 2,826 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
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])