結果

問題 No.320 眠れない夜に
ユーザー maspy
提出日時 2020-03-04 15:07:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-14 00:15:23
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10 ** 9

# %%
N, M = map(int, read().split())


# %%
F = [0] * 100
F[1] = 1
for n in range(2, 100):
    F[n] = F[n - 1] + F[n - 2]


# %%
def get_min(n, a, b):
    return (a - 1) * F[n] + (b - 1) * F[n + 1] + 1


def get_max(n, a, b):
    return a * F[n] + b * F[n + 1]


# %%
def solve(N, M, a, b):
    if N == 0:
        if b == M:
            return 0
        return INF
    if get_min(N, a, b) > M:
        return INF
    if get_max(N, a, b) < M:
        return INF
    x = solve(N - 1, M, b, a + b - 1) + 1
    if x < INF:
        return x
    return solve(N - 1, M, b, a + b)


# %%
x = solve(N - 2, M, 1, 1)
if x == INF:
    x = -1
print(x)
0