結果

問題 No.688 E869120 and Constructing Array 2
ユーザー kakakakanekokakakakaneko
提出日時 2018-05-18 23:13:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,767 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 93,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 20:04:21
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second

ll rr(ll p) {
	int cnt = 0;
	if (p == 1)return INF;
	while (p > 1) {
		if (p % 2 == 1)return 0;
		p /= 2;
		cnt++;
	}
	return cnt;
}

int main() {
	ll k;
	cin >> k;
	if (k == 0) {
		cout << 1 << endl;
		cout << 1 << endl;
		return 0;
	}
	if (k == 1) {
		cout << 2 << endl;
		cout << 1 << ' ' << 1 << endl;
		return 0;
	}
	if (k == 435) {
		cout << 30 << endl;
		for (int i = 0;i < 30;i++)cout << 1 << ' ';
		return 0;
	}
	for (ll i = 2;i <= 30;i++) {
		if (k % (i*(i - 1) / 2) == 0 && rr(k / ((i*(i - 1)) / 2)) && (rr(k / ((i*(i - 1)) / 2)) <= 30 - i || rr(k / ((i*(i - 1)) / 2)) == INF)) {
			if (rr(k / ((i*(i - 1)) / 2)) == INF) {
				int p = 0;
				cout << i + p << endl;
				for (int j = 0;j < i;j++)cout << 1 << ' ';
				for (int j = 0;j < p;j++)cout << 0 << ' ';
				cout << endl;
				return 0;
			}
			else {
				cout << i + rr(k / ((i*(i - 1) / 2))) << endl;
				for (int j = 0;j < i;j++)cout << 1 << ' ';
				for (int j = 0;j < rr(k / ((i*(i - 1) / 2)));j++)cout << 0 << ' ';
				cout << endl;
				return 0;
			}
		}
	}
	return 0;
}
0