結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
|
| 提出日時 | 2017-04-16 11:32:12 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,903 bytes |
| コンパイル時間 | 99 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-07-19 03:59:44 |
| 合計ジャッジ時間 | 6,753 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 28 |
ソースコード
# coding: utf-8
def count_1(n):
count = 0
flg = True
while (flg):
mod = n % 2
if mod==0: pass
if mod==1: count += 1
if (mod==n):
flg = False
n = int(n / 2)
return count
# Run the main function if called from the command line
if __name__ == "__main__":
# 標準入力から一行分を読み出し、文字列として格納する。
first = input()
# 読み込んだ文字列をスペースで分割する
#split_first = first.split()
# それぞれをint型に変換する
N = int(first)
# 慣れてくると この一行でよい
# A, B = map(int, input().split())
# 参考: リストを読む際はlist()で覆ってやらないといけない
# L = list(map(int, input().split()))
#2行目を読み込む
#S = input()
# 標準出力に書き出す。
# カンマで区切るとスペースで分割してくれるので楽です。
#print(A + B, S)
target_list = [N]
cand_list = []
count = 1
flg = True
while(flg):
count += 1
for target in target_list:
for i in range(1, 14):
t_pi = target + i
if target+i <= N:
if (t_pi - count_1(t_pi) == target):
cand_list.append(t_pi)
t_mi = target - i
if t_mi >= 1:
if (t_mi + count_1(t_mi) == target):
cand_list.append(t_mi)
# 終了判定
if N==1:
count = 1
flg = False
elif len(cand_list)==0:
count = -1
flg = False
else:
for i in cand_list:
if i==1:
flg = False
else:
pass
target_list = cand_list
cand_list = []
print (count)