結果

問題 No.680 作れる数
ユーザー xuzijian629xuzijian629
提出日時 2018-09-11 01:03:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,153 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 93,808 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 08:29:19
合計ジャッジ時間 2,341 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <chrono>
#include <random>
#include <functional>
#include <utility>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<i64, i64>;

bool exist(int n, int k) {
    // k exist in tree with root n
    if (n == k) return true;
    int lsum = n, l = n, rsum = n, r = n;
    while (1) {
        if (k < lsum) return false;
        lsum += l * 2;
        l = l * 2;
        rsum += r * 2 + 1;
        r = r * 2 + 1;
        if (lsum <= k && k <= rsum) {
            return exist(n * 2, k - n) || exist(n * 2 + 1, k - n);
        }
    }
}

int main() {
    int n;
    cin >> n;
    cout << ((n == 0 || exist(1, n)) ? "YES" : "NO") << endl;
}
0