結果

問題 No.320 眠れない夜に
ユーザー BantakoBantako
提出日時 2018-07-09 12:21:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,393 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 179,244 KB
実行使用メモリ 118,552 KB
最終ジャッジ日時 2023-09-22 08:36:20
合計ジャッジ時間 8,610 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> V(N);
    V[0] = V[1] = 1;
    rep(i,2,N)V[i] = V[i-1] + V[i-2];
    ll dif = V[N-1] - M;
    cout << dif << endl;

    //V[N-2]までの和でdifを表せるかどうか
    map<ll,int> mp;
    mp[0] = 0;
    rep(i,0,N-1){
        map<ll,int> mp2;
        for(auto p:mp){
            rep(k,0,2){
                ll next = V[i] + p.first;
                if(k)next = p.first;
                if(next > M)continue;
                vector<int> vec;
                vec.push_back(p.second + 1);
                if(mp2.find(next) != mp2.end() )vec.push_back(mp2[next]);
                if(mp.find(next) != mp.end() )vec.push_back(mp[next]);
                int mini = INF;
                for(auto i:vec)mini = min(mini, i);
                mp2[next] = mini;
            }
        }
        //mp = mp2;

        mp.clear();
        for(auto p:mp2){
            mp[p.first] = p.second;
           // cout << p.first << " " << p.second << endl;
        }
        //cout << "-----" << endl;
    }
    for(auto p:mp){
        //cout << p.first << " " << p.second << endl;
    }
    if(mp.find(dif) != mp.end())cout << mp[dif] << endl;
    else                      cout << -1 << endl;
}
0