結果
問題 | No.320 眠れない夜に |
ユーザー |
![]() |
提出日時 | 2021-08-27 21:09:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 825 bytes |
コンパイル時間 | 2,146 ms |
コンパイル使用メモリ | 193,728 KB |
最終ジャッジ日時 | 2025-01-24 02:20:02 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 6 |
ソースコード
#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;i>=1;i--){ if(m>=fib[i]){ res++; m-=fib[i]; } } if(m==0)cout<<res<<'\n'; else puts("-1"); return 0; }