結果

問題 No.688 E869120 and Constructing Array 2
ユーザー tactac
提出日時 2019-07-24 23:17:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 1,000 ms
コード長 1,802 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 166,592 KB
実行使用メモリ 15,548 KB
最終ジャッジ日時 2023-09-10 23:07:01
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,420 KB
testcase_01 AC 14 ms
15,344 KB
testcase_02 AC 14 ms
15,548 KB
testcase_03 AC 13 ms
15,304 KB
testcase_04 AC 14 ms
15,260 KB
testcase_05 AC 14 ms
15,284 KB
testcase_06 AC 14 ms
15,240 KB
testcase_07 AC 14 ms
15,480 KB
testcase_08 AC 13 ms
15,304 KB
testcase_09 AC 13 ms
15,264 KB
testcase_10 AC 13 ms
15,476 KB
testcase_11 AC 14 ms
15,420 KB
testcase_12 AC 14 ms
15,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int nibeki(int x) {
    int ret = 0;
    while (x % 2 == 0) {
        x /= 2;
        ret++;
    }
    if (x != 1) return -1;
    return ret;
}
int main() {
    COMinit();
    int k;
    cin >> k;
    if (k == 0) { out(1); out(0); return 0; }
    rep3(i, 2, 100000) {
        int a = (int)COM(i, 2);
        if (k / a != (double)k / a) continue;
        int tmp = nibeki(k / a);
        if (tmp == -1) continue;
        //out(tmp);
        if (i + tmp > 30) continue;
        out(i + tmp);
        rep(j, i) { if (j) cout << " "; cout << 1; }
        rep(j, tmp) { cout << " "; cout << 0; }
        cout << endl;
        break;
    }
}
/*
 1の組み合わせ
 各々にどの0をいくつとるか
 
 sample2
 5C2 = 10
 2^3 = 8
 
 
 */
0