結果
問題 | No.3 ビットすごろく |
ユーザー | compass19 |
提出日時 | 2016-06-02 03:07:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 991 ms / 5,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-07-01 07:59:27 |
合計ジャッジ時間 | 13,850 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
N = int(input()) def step(num,k=0,result=0): while 2**k <= num: k = k + 1 while k != -1: if 2**k <= num: num = num -2**k result = result + 1 k = k-1 return result square, prev = [1], [-1] def start(): global square, prev head, tail = 0, 1 while head < tail: now = square[head] s = step(now) if now-s > 0: if now-s not in square: square.append(now-s) prev.append(head) tail = tail + 1 if now+s <= N: if now+s not in square: square.append(now+s) prev.append(head) tail = tail + 1 if now+s == N: return True head = head + 1 return False def root(result=1): global square, prev k = prev[-1] while k != -1: result = result + 1 k = prev[k] print(result) if N == 1: print(1) else: if start(): root() else: print(-1)