結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2020-03-29 01:24:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 665 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 82,172 KB |
実行使用メモリ | 76,832 KB |
最終ジャッジ日時 | 2025-01-02 12:36:57 |
合計ジャッジ時間 | 3,604 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
def bc(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f N = int(input()) INF = float('inf') dp = [INF]*(N+1) dp[1] = 1 for i in range(1, N+1): c = bc(i) if i+c <= N: dp[i+c] = min(dp[i+c], dp[i]+1) if i-c >= 1: dp[i-c] = min(dp[i-c], dp[i]+1) for i in range(1, N+1): c = bc(i) if i+c <= N: dp[i+c] = min(dp[i+c], dp[i]+1) if i-c >= 1: dp[i-c] = min(dp[i-c], dp[i]+1) print(dp[N] if dp[N] < INF else -1)