結果

問題 No.688 E869120 and Constructing Array 2
ユーザー BantakoBantako
提出日時 2018-05-28 11:20:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,061 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 165,080 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 20:44:42
合計ジャッジ時間 2,448 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 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 1 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,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    6 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int K;
    cin >> K;
    int dp[33][3] = {};
    dp[0][0] = 1;
    int N = 1,zero = 1;
    if(!K){
        cout << 1 << endl << 0 << endl;
        return 0;
    }
    for(int i = 1;i <= 32;i++){
        for(int j = 0;j < 3;j++){
            dp[i][j] = dp[i-1][j];
            if(j != 0)dp[i][j] += dp[i-1][j-1];
            /*
            dp[i][j] += dp[i-1][j];
            if(j != 2)dp[i][j+1] += dp[i-1][j];
            */
        }
        //cout << dp[i][2] << endl;
        if(!dp[i][2] || K % dp[i][2] != 0)continue;
        int num = K / dp[i][2];
        //2^Nで表せるとき 
        if((num & -num) == num){
            zero = log2(num);
            N = log2(num) + i;
            break;
        }
    }
    //cout << N << " " << zero << endl;
    cout << N << endl;
    for(int i = 0;i < N;i++){
        if(zero){
            cout << 0 << endl;
            zero--;
        }else{
            cout << 1 << endl;
        }

    }
}
0