結果
問題 | No.3 ビットすごろく |
ユーザー | phantomile |
提出日時 | 2015-12-19 07:47:31 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,126 bytes |
コンパイル時間 | 128 ms |
コンパイル使用メモリ | 10,908 KB |
実行使用メモリ | 9,480 KB |
最終ジャッジ日時 | 2023-10-14 14:13:17 |
合計ジャッジ時間 | 2,612 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,748 KB |
testcase_01 | AC | 19 ms
8,688 KB |
testcase_02 | AC | 19 ms
8,816 KB |
testcase_03 | AC | 22 ms
9,096 KB |
testcase_04 | AC | 19 ms
8,844 KB |
testcase_05 | AC | 21 ms
9,052 KB |
testcase_06 | AC | 19 ms
8,932 KB |
testcase_07 | AC | 18 ms
8,928 KB |
testcase_08 | AC | 21 ms
9,080 KB |
testcase_09 | AC | 23 ms
9,196 KB |
testcase_10 | AC | 25 ms
9,424 KB |
testcase_11 | AC | 24 ms
9,228 KB |
testcase_12 | AC | 23 ms
9,096 KB |
testcase_13 | AC | 19 ms
9,044 KB |
testcase_14 | AC | 25 ms
9,308 KB |
testcase_15 | AC | 27 ms
9,356 KB |
testcase_16 | AC | 26 ms
9,376 KB |
testcase_17 | AC | 26 ms
9,460 KB |
testcase_18 | AC | 18 ms
8,968 KB |
testcase_19 | AC | 28 ms
9,308 KB |
testcase_20 | AC | 17 ms
8,720 KB |
testcase_21 | AC | 17 ms
8,820 KB |
testcase_22 | AC | 25 ms
9,376 KB |
testcase_23 | AC | 27 ms
9,480 KB |
testcase_24 | AC | 28 ms
9,316 KB |
testcase_25 | AC | 27 ms
9,372 KB |
testcase_26 | WA | - |
testcase_27 | AC | 19 ms
8,988 KB |
testcase_28 | AC | 25 ms
9,368 KB |
testcase_29 | AC | 22 ms
9,052 KB |
testcase_30 | AC | 17 ms
8,872 KB |
testcase_31 | AC | 17 ms
8,692 KB |
testcase_32 | AC | 22 ms
9,240 KB |
ソースコード
""" Yukicoder No.3 ビットすごろく author: yamaton date: 2015-12-18 """ import itertools as it import functools import operator import collections import math import sys def bitcount(n): res = 0 while n > 0: res += n & 1 n >>= 1 return res def solve(n): if n == 1: return 0 q = collections.deque() q.append(1) path_to = dict() path_to[1] = None while q: curr = q.popleft() delta = bitcount(curr) for next_ in (curr + delta, curr - delta): if next_ not in path_to and 1 <= next_ <= n: q.append(next_) path_to[next_] = curr if next_ == n: # pp(path_to) return steps_from_start(path_to, n) else: return -1 def steps_from_start(path_to, n, start=1): cnt = 1 while n != start: n = path_to[n] cnt += 1 return cnt def pp(*args, **kwargs): return print(*args, file=sys.stderr, **kwargs) def main(): n = int(input()) result = solve(n) print(result) if __name__ == '__main__': main()