結果

問題 No.688 E869120 and Constructing Array 2
ユーザー nukachanukacha
提出日時 2018-05-22 12:56:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,007 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 117,120 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 14:29:39
合計ジャッジ時間 1,505 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>

using namespace std;

long long K;

long long pow2(long long p) {
    long long r = 1;
    for (long long i = 0; i < p; i++) {
        r *= 2;
    }
    return r;
}

int main(int argc, char const *argv[])
{
    cin >> K;
    if (K == 0) {
        cout << 1 << endl;
        cout << 0 << endl;
        return 0;
    }
    long long sizeb, nzero;
    for (sizeb = 2; sizeb <= 30; sizeb++) {
        bool bf = false;
        for (nzero = 0; nzero <= sizeb - 2; nzero++) {
            if (pow2(nzero) * (sizeb - nzero) * (sizeb - nzero - 1) / 2 == K) {
                bf = true;
                break;
            }
        }
        if (bf) {
            break;
        }
    }
    cout << sizeb << endl;
    for (long long i = 0; i < nzero; i++) {
        cout << "0 ";
    }
    for (long long i = 0; i < sizeb - nzero; i++) {
        cout << "1";
        if (i != sizeb - nzero - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    return 0;
}
0