結果

問題 No.688 E869120 and Constructing Array 2
ユーザー MisterMister
提出日時 2020-04-16 10:03:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 819 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 71,292 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:07:54
合計ジャッジ時間 1,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>

constexpr int N = 30;

void solve() {
    int k;
    std::cin >> k;

    if (k == 0) {
        std::cout << 1 << std::endl
                  << 0 << std::endl;
        return;
    }

    for (int o = 2; o <= N; ++o) {
        int p = o * (o - 1) / 2;
        if (k % p != 0) continue;

        int z = 0;
        while ((1LL << z) < k / p) ++z;
        if ((1LL << z) != k / p || o + z > N) continue;

        std::cout << o + z << std::endl;
        for (int i = 0; i < o; ++i) {
            std::cout << 1 << " ";
        }
        for (int i = 0; i < z; ++i) {
            std::cout << 0 << " ";
        }
        std::cout << std::endl;
        return;
    }

    std::terminate();
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0