結果

問題 No.643 Two Operations No.2
ユーザー tubo28tubo28
提出日時 2018-02-02 21:44:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,477 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 165,636 KB
実行使用メモリ 11,916 KB
最終ジャッジ日時 2023-08-30 02:05:35
合計ジャッジ時間 8,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

namespace io {
#ifdef LOCAL
#define dump(...)                                           \
    do {                                                    \
        std::ostringstream os;                              \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";   \
        io::print_to(os, ", ", "\n", __VA_ARGS__);          \
        std::cerr << io::highlight(os.str());               \
    } while (0)
#define dump_(arr)                                  \
    do {                                            \
        std::ostringstream os;                      \
        os << __LINE__ << ":\t" << #arr << " = [";  \
        io::print_to_(os, ", ", "]\n", all(arr));   \
        std::cerr << io::highlight(os.str());       \
    } while (0)
#define dumpf(fmt, ...)                                         \
    do {                                                        \
        const int N = 65536;                                    \
        static char b[N];                                       \
        int l = snprintf(b, N, "%d:\t", __LINE__);              \
        snprintf(b + l, N - l, fmt, ##__VA_ARGS__);             \
        std::cerr << io::highlight(b) << std::endl;             \
    } while(0)
#else
#define dump(...)
#define dump_(...)
#define dumpf(...)
#endif
    std::string highlight(std::string s) {
#ifdef _MSC_VER
        return s;
#else
        return "\033[33m" + s + "\033[0m";
#endif
    }
    template <typename T>
    void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
        os << fst << tail;
    }
    template <typename Fst, typename... Rst>
    void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
        os << fst << del;
        print_to(os, del, tail, rst...);
    }
    template <typename Iter>
    void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
        for (Iter it = bgn; it != end;) {
            os << *it;
            os << (++it != end ? del : tail);
        }
    }
    template <typename Fst, typename... Rst>
    void println(const Fst &fst, const Rst &... rst) {
        io::print_to(std::cout, "\n", "\n", fst, rst...);
    }
    template <typename Fst, typename... Rst>
    void print(const Fst &fst, const Rst &... rst) {
        io::print_to(std::cout, " ", "\n", fst, rst...);
    }
    template <typename Iter>
    void println_(Iter bgn, Iter end) {
        print_to_(std::cout, "\n", "\n", bgn, end);
    }
    template <typename Iter>
    void print_(Iter bgn, Iter end) {
        print_to_(std::cout, " ", "\n", bgn, end);
    }
    int trush = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
                 std::ios::sync_with_stdio(0));
}

using io::print; using io::println; using io::println_; using io::print_;
using namespace std;
// const int MOD = 1000000007;

signed main() {
    int n;
    while (cin >> n) {
        int cnt = 0;
        while (n != 1) {
            if (n & 1) ++n;
            else n /= 2;
            ++cnt;
        }
        print(cnt);
    }
}
0