結果

問題 No.688 E869120 and Constructing Array 2
ユーザー startcppstartcpp
提出日時 2018-05-18 23:09:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 878 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 51,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 20:03:39
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//とりあえず、数列をグループ分けしたくなるので、1の個数か何かでグループ分けすると解ける。(詳細↓)
//1の個数が決まれば、何通りになるかが分かる。1の個数がa個のとき、comb[a][2] * (1 << (N - a))通りの選び方がある。
//(1を2つ選んで、0を自由に選ぶ方法の数なので)
//これがKになる、Nとaのペアを見つけてくればよい。
#include <iostream>
using namespace std;

int k;

int main() {
	cin >> k;
	
	int n, a;
	for (n = 1; n <= 30; n++) {
		for (a = 0; a <= n; a++) {
			if (k == a * (a - 1) / 2 * (1 << (n - a))) {
				break;
			}
		}
		if (a <= n) break;
	}
	
	cout << n << endl;
	for (int i = 0; i < a; i++) {
		cout << 1;
		if (i + 1 < n) cout << " ";
	}
	for (int i = a; i < n; i++) {
		cout << 0;
		if (i + 1 < n) cout << " ";
	}
	cout << endl;
	return 0;
}
0