結果

問題 No.688 E869120 and Constructing Array 2
ユーザー polylogKpolylogK
提出日時 2018-05-18 22:42:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 791 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 165,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 19:56:27
合計ジャッジ時間 2,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n;
	
	if(n == 0){
		cout << 1 << endl;
		return 0;
	}
	
	int a = 0, x = n;
	while(x % 2 == 0){
		x /= 2;
		a++;
	}
	if(x == 1){
		cout << a + 2 << endl;
		for(int i = 0; i < a; i++) cout << 0 << " ";
		cout << 1 << " " << 1 << endl;
		return 0;
	}
	
	
	for(int i = 2; i * (i + 1) / 2 <= n; i++){
		if(n % (i * (i + 1) / 2)) continue;
		
		int B = i + 1;
		int pos = n / ((i * (i + 1)) / 2);
		int A = 0;
		while(pos % 2 == 0){
			pos /= 2;
			A++;
		}
		if(pos != 1) continue;
		if(A + B > 30) continue;
		
		cout << A + B << endl;
		for(int i = 0; i < A; i++) cout << 0 << " ";
		for(int i = 0; i < B; i++) cout << 1 << " ";
		cout << endl;
		return 0;
	}
	assert(false);
	
	return 0;
}
0