結果

問題 No.2426 Select Plus or Minus
ユーザー Manuel1024Manuel1024
提出日時 2023-08-18 21:36:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,170 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 96,496 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-18 21:36:41
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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>;

int main(){
    ll n; cin >> n;

    map<ll, int> mem;
    map<ll, ll> pre;
    queue<ll> Q;
    Q.emplace(n);
    mem[n] = 0;
    while(!Q.empty()){
        ll cur = Q.front(); Q.pop();
        if(cur == 1) break;
        if(cur%2 == 0){
            if(mem.count(cur/2) == 1) continue;
            mem[cur/2] = mem[cur]+1;
            pre[cur/2] = cur;
            if(cur/2 == 1) break;
            Q.emplace(cur/2);
        }else{
            for(auto &it: {cur*3+1}){
                if(mem.count(it) == 1) continue;
                mem[it] = mem[cur]+1;
                pre[it] = cur;
                if(it == 1) break;
                Q.emplace(it);
            }
        }
    }

    string ans = "";
    ll x = 1;
    while(x != n){
        ll p = pre[x];
        if(x*2 == p) ans += "/";
        else if(p*3+1 == x) ans += "+";
        else ans += "-";
        x = p;
    }
    reverse(ans.begin(), ans.end());
    cout << ans.size() << endl;
    cout << ans << endl;
    return 0;
}
0