結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-01-02 23:15:28 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 499 bytes |
| 記録 | |
| コンパイル時間 | 346 ms |
| コンパイル使用メモリ | 85,632 KB |
| 実行使用メモリ | 312,108 KB |
| 最終ジャッジ日時 | 2026-05-16 18:45:03 |
| 合計ジャッジ時間 | 10,548 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 1 -- * 23 |
ソースコード
from heapq import *
import sys
def II(): return int(sys.stdin.readline())
def main():
n=II()
hp=[]
heappush(hp,[1,1])
cnt=[-1]*(n+1)
while hp:
c,u=heappop(hp)
if u==n:
print(c)
exit()
d=bin(u).count("1")
if u+d==n or u-d==n:
print(c+1)
exit()
cnt[u]=c
if u+d<=n and cnt[u+d]==-1:heappush(hp,[c+1,u+d])
if u-d>1 and cnt[u-d]==-1:heappush(hp,[c+1,u-d])
print(-1)
main()
mkawa2