记录编号 605708 评测结果 AAAAAAAAAAAAAAAAAA
题目名称 4170.[USACO25 Open Silver]Sequence Construction 最终得分 100
用户昵称 Gravatarxxz 是否通过 通过
代码语言 C++ 运行时间 0.399 s
提交时间 2025-09-06 16:22:11 内存使用 3.71 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int T, m, k, x, d, flag;
vector<int> a, b;
int main()
{
	freopen("Sequence.in", "r", stdin);
	freopen("Sequence.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> T;
	while (T--)
	{
		a.clear();
		b.clear();
		cin >> m >> k;
		x = 0;
		for (int i = 0; i < 5; i++)
			if (k & (1 << i))
			{
				a.push_back((1 << (1 << i)) - 1);
				x += a.back();
			}
		d = m - x;
		flag = 0;
		if (d < 0)
			flag = 1;
		else if (d >= 2)
		{
			if (d % 2 == 0)
				b = {d / 2, d / 2};
			else
				b = {1, 2, (d - 3) / 2, (d - 3) / 2};
		}
		else if (d == 0)
			b.clear();
		else if (a[0] == 1)
			a[0] = 2;
		else
			flag = -1;
		if (flag)
			cout << "-1\n";
		else
		{
			cout << a.size() + b.size() << endl;
			for (int v : a)
				cout << v << " ";
			for (int v : b)
				cout << v << " ";
			cout << endl;
		}
	}
	return 0;
}