結果

問題 No.688 E869120 and Constructing Array 2
ユーザー phsplsphspls
提出日時 2020-04-22 23:54:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,050 bytes
コンパイル時間 1,523 ms
コンパイル使用メモリ 166,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 13:52:32
合計ジャッジ時間 2,024 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long

int main() {
    int k;
    cin >> k;
    int korg = k;
    if(k==0) {
        cout << 1 << endl;
        cout << 0 << endl;
        return 0;
    }

    int twices = 0;
    while(k % 2 == 0) {
        k /= 2;
        twices++;
    }
    vector<int> cands;
    for(int i=1; i<31; i++) {
        int val = i * (i+1) / 2;
        if(val % k == 0) {
            cands.push_back(i);
        }
    }
    for(int lowval: cands) {
        int val = lowval * (lowval+1) / 2;
        int rest = korg / val;
        int zeroval = 0;
        while(rest % 2 == 0) {
            rest /= 2;
            zeroval++;
        }
        if(lowval + 1 + zeroval <= 30) {
            cout << lowval + 1 + zeroval << "\n";
            rep(i, zeroval) cout << "0 ";
            rep(i, lowval+1) {
                cout << "1";
                if(i < lowval) cout << " ";
            }
            cout << "\n";
            return 0;
        }
    }
}
0