제출 #1148242

#제출 시각아이디문제언어결과실행 시간메모리
1148242stdfloatBinary Subsequences (info1cup17_binary)C++20
82 / 100
1095 ms4124 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
	int k;
	cin >> k;

	string ans;
	int cnt = 0;
	for (int i = 0; i <= k; i++) {
		string s;
		int x = i, y = k - i;
		while (x || y) {
			if (x > y) {
				for (int j = 0; j < x / (y + 1); j++)
					s += '1';

				x %= (y + 1);
			}
			else if (x < y) {
				for (int j = 0; j < y / (x + 1); j++)
					s += '0';
			
				y %= (x + 1);
			}
			else {
				s.clear();
				break;
			}
		}

		if (!s.empty()) {
			cnt++;
			if (ans.empty() || (int)ans.size() > (int)s.size()) ans = s;
		}
	}

	cout << cnt << '\n';
	for (auto i : ans)
		cout << i << ' ';
	cout << '\n';
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int T;
	cin >> T;
	while (T--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...