結果

問題 No.688 E869120 and Constructing Array 2
ユーザー aaaaaa
提出日時 2018-07-18 11:04:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,362 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 93,812 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 17:48:48
合計ジャッジ時間 1,357 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>

using namespace std;


int main() {
	long i, j;
	int k;

	cin >> k;

	if (k == 0) {
		cout << 1 << endl;
		cout << 0 << endl;
		return 0;
	}

	for (i = 2; i <= 30; i++) {
		long num = 0;
		for (int h = i - 1; h >= 1; h--) {
			num += h;
		}
		
	//	cout << "num->" << num << endl;

		if (num == k) {
			cout << i << endl;
			for (i; i > 0; i--) {
				cout << 1;
				if (i - 1 != 0) {
					cout << " ";
				}
				else {
					cout << endl;
				}
			}
			getchar();
			getchar();
			return 0;
		}

		for (j = 1; j <= 30 - i; j++) {
			//long num2 = j*i + i;
			long num2 = ( pow(2,j)-1) * num + num;
		//	cout << "num2->" << num2 << endl;
		//	cout << "j->" << j << "  i->" << i << endl << endl;

			if (num2 > k) break;

			if (num2 == k) {
				cout << j + i << endl;
				for (int jj = 0; jj < j; jj++) {
					cout << 0 << " ";
				}
				for (int jj = 0; jj < i; jj++) {
					cout << 1;
					if (jj + 1 != i) {
						cout << " ";
					}
					else {
						cout << endl;
					}
				}

				getchar();
				getchar();
				return 0;
			}

		}
	}











	getchar();
	getchar();
	return 0;
}
0