結果
問題 | No.3 ビットすごろく |
ユーザー | stnkien |
提出日時 | 2020-03-29 01:24:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 665 bytes |
コンパイル時間 | 844 ms |
コンパイル使用メモリ | 87,124 KB |
実行使用メモリ | 77,604 KB |
最終ジャッジ日時 | 2023-08-30 18:24:53 |
合計ジャッジ時間 | 5,379 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,192 KB |
testcase_01 | AC | 72 ms
71,304 KB |
testcase_02 | AC | 73 ms
71,096 KB |
testcase_03 | AC | 121 ms
76,312 KB |
testcase_04 | WA | - |
testcase_05 | AC | 105 ms
77,188 KB |
testcase_06 | AC | 93 ms
76,484 KB |
testcase_07 | AC | 84 ms
76,296 KB |
testcase_08 | AC | 102 ms
77,120 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 104 ms
77,020 KB |
testcase_13 | AC | 87 ms
76,616 KB |
testcase_14 | AC | 109 ms
77,268 KB |
testcase_15 | AC | 112 ms
77,244 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 86 ms
76,232 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 69 ms
71,564 KB |
testcase_22 | AC | 107 ms
77,152 KB |
testcase_23 | AC | 111 ms
77,292 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 69 ms
71,140 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 69 ms
71,052 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
ソースコード
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)