結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 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);
}

int main(void){
    
    cin >> K;
    
    if(K == 0) {
        cout << 1 << endl << 0 << endl;
        return 0;
    }
    
    for(int i = 0; i <= 30; ++i){
        int p = pow(2, i);
        for(int j = 0; i + j <= 30; ++j){
            int c = (j >= 2) ? Combi(j, 2) : 0;
            if(p * c == K){
                cout << i + j << endl;
                for(int k = 0; k < i; ++k) cout << 0 << " ";
                for(int k = 0; k < j; ++k){
                    if(k) cout << " ";
                    cout << 1;
                }
                cout << endl;
                return 0;
            }
        }
    }
    
    return 0;
}
0