結果

問題 No.2426 Select Plus or Minus
ユーザー Manuel1024
提出日時 2023-08-18 23:25:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 76,392 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 10:39:40
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;
class Error1{};
string ans = "";

void dfs(ll x){
    if(10000 < ans.size()) return;
    if(x == 1){
        cout << ans.size() << endl;
        cout << ans << endl;
        throw Error1{};
    }
    if(x%2 == 0){
        ans += "/";
        dfs(x/2);
        ans.pop_back();
    }else{
        if(x*3+1 <= 1000000000000000000){
            ans += "+";
            dfs(x*3+1);
            ans.pop_back();
        }
        if(x*3-1 <= 1000000000000000000){
            ans += "-";
            dfs(x*3-1);
            ans.pop_back();
        }
    }
}

int main(){
    ll n; cin >> n;
    try{
        dfs(n);
    }catch(Error1 &e){

    };
    return 0;
}
0