結果
問題 | No.320 眠れない夜に |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:43:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 721 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,276 KB |
実行使用メモリ | 53,956 KB |
最終ジャッジ日時 | 2025-03-20 20:43:11 |
合計ジャッジ時間 | 2,703 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
n, m = map(int, input().split()) # Calculate the standard Fibonacci sequence up to n fib = [0] * (n + 1) fib[1] = 1 if n >= 2: fib[2] = 1 for i in range(3, n + 1): fib[i] = fib[i-1] + fib[i-2] fn = fib[n] d = fn - m if d < 0: print(-1) elif d == 0: print(0) else: # Collect the possible Fib(k) values for each i from 3 to n candidates = [] for i in range(3, n + 1): k = n - i + 1 if k >= 1: candidates.append(fib[k]) count = 0 current_d = d for num in candidates: if current_d >= num: current_d -= num count += 1 if current_d == 0: break print(count if current_d == 0 else -1)