結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-08-12 19:57:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 878 bytes |
コンパイル時間 | 672 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-11-07 12:13:27 |
合計ジャッジ時間 | 5,240 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 4 RE * 15 |
ソースコード
def get_bitnum(n): i = 0 while n > 0: if n % 2 == 1: i += 1 n = n // 2 return i def create_route(N): route = [get_bitnum(i+1) for i in range (N)] return route N = int(input()) route = create_route(N) history = [] res = [] def search(pos, time): if pos == N-1: res.append(time) else: history.append(pos) bitnum = route[pos] posR = pos + bitnum posL = pos - bitnum RB = not (posR > N-1 or posR in history) LB = not (posL < 1 or posL in history) if RB and LB: return search(posR, time+1), search(posL, time+1) elif RB and not LB: return search(posR, time+1) elif LB and not RB: return search(posL, time+1) else: pass search(0, 1) if res == []: print(-1) else: print(min(res))