记录编号 605714 评测结果 AAAAAAAAAAAAAAAAAA
题目名称 4170.[USACO25 Open Silver]Sequence Construction 最终得分 100
用户昵称 Gravatarwdsjl 是否通过 通过
代码语言 C++ 运行时间 0.382 s
提交时间 2025-09-06 16:42:58 内存使用 3.70 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll m, k, a[110], tot = 0;

void Solve() {
    tot = 0;
    cin >> m >> k;
    
    for (int i = 5; i >= 0; --i) {
        if (k & (1 << i)) {
            ll cur = (1 << (1 << i)) - 1;
            m -= cur;
            a[++tot] = cur;
            if (m < 0) {
                cout << -1 << '\n';
                return;
            }
        }
    }
    
    if (m == 1) {
        if (a[tot] != 1) {
            cout << -1 << '\n';
            return;
        }
        ++a[tot];
    } else if (m % 2 == 0) {
        a[++tot] = m / 2;
        a[++tot] = m / 2;
    } else {
        a[++tot] = 1;
        a[++tot] = 2;
        a[++tot] = (m - 3) / 2;
        a[++tot] = (m - 3) / 2;
    }
    
    cout << tot << '\n';
    for (int i = 1; i <= tot; ++i) {
        cout << a[i] << ' ';
    }
    cout << '\n';
}

int main() {
	freopen("Sequence.in","r",stdin);
	freopen("Sequence.out","w",stdout);
    ll T;
    cin >> T;
    while (T--) {
        Solve();
    }
    return 0;
}