結果

問題 No.887 Collatz
ユーザー tactac
提出日時 2019-09-20 21:26:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 164,664 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2023-10-12 17:48:04
合計ジャッジ時間 2,697 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,296 KB
testcase_01 AC 5 ms
11,172 KB
testcase_02 AC 6 ms
11,108 KB
testcase_03 AC 6 ms
11,196 KB
testcase_04 AC 6 ms
11,292 KB
testcase_05 AC 5 ms
11,232 KB
testcase_06 AC 5 ms
11,112 KB
testcase_07 AC 5 ms
11,156 KB
testcase_08 AC 6 ms
11,140 KB
testcase_09 AC 6 ms
11,132 KB
testcase_10 AC 5 ms
11,092 KB
testcase_11 AC 6 ms
11,108 KB
testcase_12 AC 6 ms
11,124 KB
testcase_13 AC 6 ms
11,296 KB
testcase_14 AC 6 ms
11,112 KB
testcase_15 AC 6 ms
11,148 KB
testcase_16 AC 6 ms
11,196 KB
testcase_17 AC 6 ms
11,144 KB
testcase_18 AC 6 ms
11,160 KB
testcase_19 AC 6 ms
11,108 KB
testcase_20 AC 6 ms
11,292 KB
testcase_21 AC 5 ms
11,112 KB
testcase_22 AC 6 ms
11,088 KB
testcase_23 AC 6 ms
11,168 KB
testcase_24 AC 6 ms
11,172 KB
testcase_25 AC 7 ms
11,088 KB
testcase_26 AC 6 ms
11,156 KB
testcase_27 AC 6 ms
11,224 KB
testcase_28 AC 5 ms
11,108 KB
testcase_29 AC 6 ms
11,112 KB
testcase_30 AC 6 ms
11,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    int n;
    cin >> n;
    const int maxn = 1000000;
    ll table[maxn] = {0};
    table[0] = n;
    rep(i, maxn - 1) {
        if (table[i] % 2 == 0) {
            table[i + 1] = table[i] / 2;
        } else {
            table[i + 1] = 3 * table[i] + 1;
        }
    }
    int ans = -1;
    rep(i, maxn) if (table[i] == 1) { ans = i; break; }
    ll maxx = -1;
    rep(i, ans + 1) chmax(maxx, table[i]);
    cout << ans << endl << maxx << endl;
}
0