結果
問題 | No.3 ビットすごろく |
ユーザー | asaka189 |
提出日時 | 2018-01-31 15:01:14 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 11,068 KB |
実行使用メモリ | 8,692 KB |
最終ジャッジ日時 | 2023-09-14 00:53:59 |
合計ジャッジ時間 | 2,357 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,272 KB |
testcase_01 | AC | 17 ms
8,196 KB |
testcase_02 | AC | 17 ms
8,356 KB |
testcase_03 | AC | 22 ms
8,348 KB |
testcase_04 | AC | 18 ms
8,288 KB |
testcase_05 | AC | 27 ms
8,404 KB |
testcase_06 | AC | 22 ms
8,388 KB |
testcase_07 | AC | 20 ms
8,204 KB |
testcase_08 | AC | 25 ms
8,316 KB |
testcase_09 | AC | 31 ms
8,232 KB |
testcase_10 | AC | 33 ms
8,564 KB |
testcase_11 | AC | 29 ms
8,380 KB |
testcase_12 | AC | 26 ms
8,440 KB |
testcase_13 | AC | 20 ms
8,400 KB |
testcase_14 | AC | 32 ms
8,440 KB |
testcase_15 | AC | 36 ms
8,580 KB |
testcase_16 | AC | 35 ms
8,576 KB |
testcase_17 | AC | 37 ms
8,500 KB |
testcase_18 | AC | 20 ms
8,412 KB |
testcase_19 | AC | 37 ms
8,504 KB |
testcase_20 | AC | 18 ms
8,264 KB |
testcase_21 | AC | 17 ms
8,368 KB |
testcase_22 | AC | 32 ms
8,492 KB |
testcase_23 | AC | 37 ms
8,692 KB |
testcase_24 | AC | 37 ms
8,576 KB |
testcase_25 | AC | 37 ms
8,576 KB |
testcase_26 | AC | 17 ms
8,216 KB |
testcase_27 | AC | 21 ms
8,396 KB |
testcase_28 | AC | 34 ms
8,464 KB |
testcase_29 | AC | 29 ms
8,464 KB |
testcase_30 | AC | 18 ms
8,360 KB |
testcase_31 | AC | 17 ms
8,272 KB |
testcase_32 | AC | 28 ms
8,496 KB |
ソースコード
def bitget(a): s = str(bin(a)) n = len(s) counter = 0 for i in range(n): if s[i] == '1': counter += 1 return counter n = int(input()) table = [0 for i in range(n+1)] table[1] = 1 q = [1] next = 0 while len(q) != 0: if len(q) == 1: next = bitget(q[0]) if table[q[0]-next] == 0: table[q[0]-next] = table[q[0]]+1 q.append(q[0]-next) if q[0]+next <= n and table[q[0]+next] == 0: table[q[0]+next] = table[q[0]]+1 q.append(q[0]+next) q.pop(0) else: k = len(q) for i in range(k): next = bitget(q[i]) if table[q[i]-next] == 0: table[q[i]-next] = table[q[i]]+1 q.append(q[i]-next) if q[i]+next <= n and table[q[i]+next] == 0: table[q[i]+next] = table[q[i]]+1 q.append(q[i]+next) for i in range(k): q.pop(0) if table[n] != 0: print(table[n]) else: print('-1')