結果

問題 No.688 E869120 and Constructing Array 2
ユーザー saitamansaitaman
提出日時 2018-07-23 09:00:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,119 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 85,888 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 01:10:20
合計ジャッジ時間 1,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
using namespace std;

long long int pow(long long int n, long long int c0){
    if(c0 == 0){
        return 1;
    }else if(c0%2==0){
        return pow(n*n, c0/2);
    }else{
        return n * pow(n, c0-1);
    }
}

long long int calc(long long int n, long long int c0, long long int c1){
    return c1 * (c1-1) / 2 * pow(n, c0);
}

int main(){
    long long int k;
    cin >> k;
    long long int ans;
    int flag = 0;
    int l;
    
    int i = 0;
    int j = 0;
    
    for(i = 1; i <= 30; i++){
        for(j = 0; j <= i; j++){
            ans = calc(2, j, i-j);
            if(ans == k){
                flag = 1;
                break;
            }
        }
        if(flag){
            break;
        }
    }
    
    cout << i << endl;
    
    for(l = 0; l < j; l++){
        printf("%d ", 0);
    }
    for(l = 0; l < i-j; l++){
        printf("%d ", 1);
    }
    printf("\n");
}
0