結果

問題 No.680 作れる数
ユーザー PachicobuePachicobue
提出日時 2018-04-27 23:45:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 1,927 ms
コンパイル使用メモリ 198,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 07:00:51
合計ジャッジ時間 2,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

int main()
{
    ll N;
    cin >> N;
    if (N == 0) {
        cout << "YES" << endl;
        return 0;
    }
    int depth = 0;
    for (ll minimum = 1; minimum <= N; minimum = 2 * minimum + 1) {
        depth++;
    }
    ll s = 1;
    ll t = 1;
    for (int i = 0; i < depth; i++) {
        ll sum = 0;
        for (ll j = i + 1, tmp = t * 2; j < depth; j++, tmp = 2 * tmp + 1) {
            sum += tmp;
        }
        if (s + sum == N) {
            cout << "YES" << endl;
            return 0;
        }
        if (s + sum < N) {
            s += t * 2 + 1;
            t = t * 2 + 1;
        } else {
            s += t * 2;
            t = t * 2;
        }
    }
    cout << (s == N ? "YES" : "NO") << endl;
    return 0;
}
0