結果

問題 No.1286 Stone Skipping
ユーザー sister_DB
提出日時 2021-02-28 20:35:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 601 bytes
コンパイル時間 1,132 ms
コンパイル使用メモリ 65,664 KB
最終ジャッジ日時 2025-01-19 08:18:48
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1 TLE * 1
other AC * 5 WA * 6 TLE * 15
権限があれば一括ダウンロードができます

ソースコード

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