結果

問題 No.2426 Select Plus or Minus
コンテスト
ユーザー scaler
提出日時 2024-09-01 13:16:49
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 981µs
コード長 867 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,215 ms
コンパイル使用メモリ 154,076 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-05 01:05:53
合計ジャッジ時間 4,142 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdint>
#include <iostream>
#include <sstream>

int main() {
    std::uint64_t a, b;
    std::cin >> a;
    std::stringstream ss;
    int n = 0;
    while (a != 1) {
        if (a % 4 == 0) {
            n += 2;
            a >>= 2;
            ss << "//";
        }
        else if (a % 4 == 1) {
            n += 1;
            b = a;
            a = 3 * a + 1;           
            if (a > 1000000000000000000ULL) {
                a = 3 * b - 1;
                ss << "-";
            }
            else {
                ss << "+";
            }
        }
        else if (a % 4 == 2) {
            n += 1;
            a >>= 1;
            ss << "/";
        }
        else /* a % 4 == 3 */ {
            n += 1;
            a = 3 * a - 1;
            ss << "-";
        }
    }
    std::cout
        << n << '\n'
        << ss.str() << std::endl;
}
0