結果
問題 | No.320 眠れない夜に |
ユーザー |
![]() |
提出日時 | 2021-08-27 21:10:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 193,552 KB |
最終ジャッジ日時 | 2025-01-24 02:20:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;//template#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)#define ALL(v) (v).begin(),(v).end()using ll=long long int;const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}int main(){int n;ll m;cin>>n>>m;vector<ll> fib(n+1);fib[1]=fib[2]=1;rep(i,3,n+1)fib[i]=fib[i-1]+fib[i-2];if(fib[n]<m){puts("-1");return 0;}int res=0;m=fib[n]-m;for(int i=n-2;i>=1;i--){if(m>=fib[i]){res++;m-=fib[i];}}if(m==0)cout<<res<<'\n';else puts("-1");return 0;}