結果
問題 | No.320 眠れない夜に |
ユーザー |
|
提出日時 | 2016-06-22 03:18:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 815 bytes |
コンパイル時間 | 942 ms |
コンパイル使用メモリ | 81,200 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 19:12:52 |
合計ジャッジ時間 | 2,128 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <iostream>#include <map>#include <tuple>typedef long long ll;using namespace std;const int inf = 1e9+7;ll upper(ll a, ll b, int n) { return n ? upper(b, a+b, n-1) : b; }ll lower(ll a, ll b, int n) { return n ? lower(b, a+b-1, n-1) : b; }map<tuple<ll,ll,int,ll>,int> memo;int go(ll a, ll b, int n, ll m) {auto key = make_tuple(a, b, n, m);if (memo.count(key)) return memo[key];if (n == 0) return memo[key] = b == m ? 0 : inf;if (upper(a, b, n) < m) return memo[key] = inf;if (lower(a, b, n) > m) return memo[key] = inf;int up = go(b, a+b, n-1, m);int dn = go(b, a+b-1, n-1, m) + 1;return memo[key] = min(up, dn);}int main() {int n; ll m; cin >> n >> m;int ans = go(1, 1, n-2, m);cout << (ans == inf ? -1 : ans) << endl;return 0;}