結果

問題 No.320 眠れない夜に
ユーザー kimiyukikimiyuki
提出日時 2016-06-22 03:18:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 81,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 00:14:05
合計ジャッジ時間 1,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0