結果

問題 No.1286 Stone Skipping
ユーザー sister_DBsister_DB
提出日時 2021-02-28 20:35:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 601 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 69,916 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-12 10:16:50
合計ジャッジ時間 4,301 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,880 KB
testcase_01 WA -
testcase_02 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

long long rec(long long num, long long dis){
    if(num > dis){
        return -1;
    }
    if(num == dis){
        return num;
    }
    
    int res1 = rec(num * 2, dis - num);
    int res2 = rec(num * 2 + 1, dis - num);
    
    if(res1 == -1 && res2 == -1){
        return -1;
    }
    if(res1 == -1){
        return res2;
    }
    if(res2 == -1){
        return res1;
    }
    if(res1 < res2){
        return res1;
    }else{
        return res2;
    }
    
}

int main(){
    long long d;
    cin >> d;
    cout << rec(1, d) << endl;
    return 0;
}
0