結果
問題 | No.320 眠れない夜に |
ユーザー |
|
提出日時 | 2023-03-01 22:02:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 560 bytes |
コンパイル時間 | 2,246 ms |
コンパイル使用メモリ | 168,472 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 19:08:32 |
合計ジャッジ時間 | 3,247 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ios::sync_with_stdio(false);cin.tie(0);ll n, m, ans = 1ll << 62;cin >> n >> m;vector<ll> a(n);a[0] = a[1] = 1;for(int i = 2; i < n; i++){a[i] = a[i - 1] + a[i - 2];}auto f = [&](ll v){ll res = 0;for(int i = n - 3; i >= 0; i--){if(v >= a[i]){v -= a[i];res++;}}return v == 0 ? res : -1;};cout << f(a.back() - m) << '\n';}