比赛 |
2025.9.6 |
评测结果 |
AAAAAAAAAAAAAAAAAA |
题目名称 |
Sequence Construction |
最终得分 |
100 |
用户昵称 |
淮淮清子 |
运行时间 |
0.408 s |
代码语言 |
C++ |
内存使用 |
3.69 MiB |
提交时间 |
2025-09-06 09:19:58 |
显示代码纯文本
#include<iostream>
#include<vector>
using namespace std;
int T;
int M, K;
int main(){
freopen("Sequence.in", "r", stdin);
freopen("Sequence.out", "w", stdout);
cin >> T;
while(T --){
cin >> M >> K;
vector<int> ans;
int cnt = 0;
bool flag = false;
for(int i = 4;i >= 0;i --){
int op = (K >> i) & 1;
if(op){
int now = (1 << (1 << i)) - 1;
ans.push_back(now);
cnt += now;
if(now == 1){
flag = true;
}
}
}
cnt = M - cnt;
if(cnt == 0){
cout << ans.size() << '\n';
for(int x : ans) cout << x << ' ';
cout << '\n';
}
else if(cnt < 0){
cout << -1 << '\n';
}
else if(cnt == 1){
if(flag){
cout << ans.size() << '\n';
for(int x : ans){
if(flag && x == 1){
cout << 2 << ' ';
flag = false;
}
else cout << x << ' ';
}
cout << '\n';
}
else{
cout << -1 << '\n';
}
}
else if(cnt % 2 == 0){
ans.push_back(cnt >> 1);
ans.push_back(cnt >> 1);
cout << ans.size() << '\n';
for(int x : ans) cout << x << ' ';
cout << '\n';
}
else{
ans.push_back(1);
ans.push_back(2);
ans.push_back((cnt - 3) >> 1);
ans.push_back((cnt - 3) >> 1);
cout << ans.size() << '\n';
for(int x : ans) cout << x << ' ';
cout << '\n';
}
}
return 0;
}