比赛 2025.9.6 评测结果 AWTTTTTTTTTTTTTTTT
题目名称 Sequence Construction 最终得分 6
用户昵称 对立猫猫对立 运行时间 47.994 s
代码语言 C++ 内存使用 3.65 MiB
提交时间 2025-09-06 10:21:07
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
#define lowbit(x) (x & (-x))
using namespace std;
int T;
vector<int> ans;
signed main() {
	freopen("Sequence.in", "r", stdin);
	freopen("Sequence.out", "w", stdout);
	cin >> T;
	while (T--) {
		int m, k;
		cin >> m >> k;
		if (__builtin_popcount(m) == k) cout << 1 << endl << m << endl;
		else {
			int t = k, check = 0;
			int mlast = m;
			while (t) {
				ans.push_back((1 << lowbit(t)) - 1);
				mlast -= (1 << lowbit(t)) - 1;
				t -= lowbit(t);
			}
			if (mlast < 0) cout << -1 << endl;
			else if (mlast == 0) {
output:
				cout << ans.size() << endl;
				for (int i = 0; i < ans.size(); i++) {
					check ^= __builtin_popcount(ans[i]);
					cout << ans[i] << " ";
				}
				cout << endl;
			} else if (mlast == 1) {
calc:
				for (int i = 0; i < ans.size(); i++) {
					if (ans[i] == 1) ans[i] = 2;
					goto output;
				}
				cout << -1 << endl;
			} else {
				if (!(mlast & 1)) {
					ans.push_back(mlast / 2);
					ans.push_back(mlast / 2);
					goto output;
				} else {
					ans.push_back(1);
					ans.push_back(2);
					mlast -= 3;
					ans.push_back(mlast / 2);
					ans.push_back(mlast / 2);
					goto output;
				}
			}
			//cout << "checked:" << check << endl;
		}
	}
	return 0;
}