結果

問題 No.688 E869120 and Constructing Array 2
ユーザー srup٩(๑`н´๑)۶
提出日時 2018-06-09 13:20:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 779 bytes
コンパイル時間 1,331 ms
コンパイル使用メモリ 158,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 14:15:24
合計ジャッジ時間 1,971 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)


ll ncr(ll n, ll r) {
	if (n == 0 || r == 0) return 1ll;

	ll sum = 1;
	for (ll i = n - r + 1; i <= n; ++i) {
		sum *= i;
	}
	for (ll i = 1; i <= r; ++i) {
		sum /= i;
	}
	return sum;
}

int main(int argc, char const *argv[])
{
	ll n; cin >> n;
	if(n == 0) {
		printf("1\n");
		printf("0\n");
		return 0;
	}

	for (int i = 2; i <= 30; ++i) {
		for (int j = 0; j <= i - 2; ++j) {
			ll d0 = j, d1 = i - j;
			ll ans = 0;
			ans = ncr(d1, 2) * pow(2, d0);
			if (ans == n) {
				cout << d0 + d1 << endl;
				rep(d, d0) cout << "0 ";
				rep(d, d1) cout << "1 ";
				cout << endl;
				goto END;
			}
		}
		
	}
END:
	return 0;
}
0