結果
問題 |
No.320 眠れない夜に
|
ユーザー |
|
提出日時 | 2021-04-24 23:57:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 620 bytes |
コンパイル時間 | 6,377 ms |
コンパイル使用メモリ | 191,116 KB |
最終ジャッジ日時 | 2025-01-21 00:42:40 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long fib[80+1]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); fib[0] = 0; fib[1] = 1; for (int i = 2; i <= 80; i++) fib[i] = fib[i-1] + fib[i-2]; int n; long long m; cin >> n >> m; if (m > fib[n]) cout << -1 << endl; else if (m == fib[n]) cout << 0 << endl; else { long long x = fib[n] - m; int ret = 0; for (int i = n-2; i > 0; i--) { if (x >= fib[i]) { ++ret; x -= fib[i]; } } if (x == 0) cout << ret << endl; else cout << -1 << endl; } return 0; }