結果

問題 No.688 E869120 and Constructing Array 2
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-26 12:18:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 993 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 145,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 20:44:09
合計ジャッジ時間 2,200 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define MAX 1073741823

using namespace std;

int K;
int num[31] = {0};

int dp[31][3];
int Combi(int n, int r){
    if(n == r) return dp[n][r] = 1;
    if(r == 0) return dp[n][r] = 1;
    if(r == 1) return dp[n][r] = n;
    if(dp[n][r]) return dp[n][r];
    return dp[n][r] = Combi(n - 1, r) + Combi(n - 1, r - 1);
}

void rec(int zero = 0, int one = 0, int count = 0){
    
    int c = (one >= 2) ? Combi(one, 2) : 0;
    int p = pow(2, zero);
    
    if(count > 30) return;
    if(c * p > K) return;
    if(c * p == K){
        cout << count << endl;
        for(int i = 0; i < count; ++i){
            if(i) cout << " ";
            cout << num[i];
        }
        cout << endl;
        exit(0);
    }
    
    num[count] = 0;
    rec(zero + 1, one, count + 1);
    num[count] = 1;
    rec(zero, one + 1, count + 1);
    
    return;
}

int main(void){
    
    cin >> K;
    
    if(K == 0) cout << 1 << endl << 0 << endl;
    else rec();
    
    return 0;
}
0