結果

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

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

void solve() {
    long long n;
    std::cin >> n;
    std::vector<char> op;
    while (n != 1) {
        if (n % 2 == 0) {
            op.push_back('/');
            n /= 2;
        } else {
            n *= 3;
            if (n & (1 << 1)) {
                op.push_back('+');
                n++;
            } else {
                op.push_back('-');
                n--;
            }
        }
    }
    std::cout << op.size() << std::endl;
    for (auto c: op) {
        std::cout << c;
    }
    std::cout << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    //  std::cin >> t;
    while (t--) nono::solve();
}
0