結果

問題 No.688 E869120 and Constructing Array 2
ユーザー outlineoutline
提出日時 2021-01-06 18:05:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,026 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 137,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:57:34
合計ジャッジ時間 2,401 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int K;
    cin >> K;
    if(K == 0){
        cout << 1 << '\n' << 0 << '\n';
        return 0;
    }

    constexpr int MAX = 30;
    vector<vector<int>> comb(MAX + 1, vector<int>(MAX + 1));
    for(int i = 0; i <= MAX; ++i)   comb[i][0] = comb[i][i] = 1;
    for(int i = 2; i <= MAX; ++i){
        for(int j = 1; j < i; ++j){
            comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
        }
    }
    vector<int> pow2(MAX + 1, 1);
    for(int i = 1; i <= MAX; ++i)   pow2[i] = pow2[i - 1] * 2;
    
    vector<int> ans;
    for(int i = 2; i <= MAX; ++i){
        for(int k = 0; k <= MAX - i; ++k){
            if((ll)comb[i][2] * pow2[k] == K){
                for(int j = 0; j < k; ++j)  ans.emplace_back(0);
                for(int j = 0; j < i; ++j)  ans.emplace_back(1);
                break;
            }
        }
        if(ans.size() > 0)  break;
    }

    int N = ans.size();
    cout << N << '\n';
    for(int i = 0; i < N; ++i){
        cout << ans[i] << ((i == N - 1) ? '\n' : ' ');
    }

    return 0;
}
0