Advertisement
Guest User

Untitled

a guest
Apr 10th, 2024
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define all(x) begin(x), end(x)
  6. #define sz(x) static_cast<int>((x).size())
  7. #define int long long
  8.  
  9.  
  10.  
  11. signed main() {
  12.  
  13. ios::sync_with_stdio(0);
  14. cin.tie(0);
  15.  
  16.  
  17. int t;
  18. cin >> t;
  19.  
  20. while (t--) {
  21.  
  22. int n, s;
  23. cin >> n >> s;
  24.  
  25. if (s & 1 || n > s || n == 1) {
  26. cout << -1 << "\n";
  27. continue;
  28. }
  29.  
  30. int dp[30] = {0};
  31. for (int i = 0; i < 30; i++) {
  32. if (s & (1ll << i)) dp[i]++;
  33. }
  34.  
  35. for (int i = 29; i > 0; i--) {
  36. if (dp[i] & 1) dp[i - 1] += 2, dp[i]--;
  37. int ex = (n - dp[i - 1]) / 2;
  38. if (ex & 1) ex--;
  39. dp[i - 1] += min(ex, dp[i]) * 2;
  40. dp[i] -= min(ex, dp[i]);
  41. }
  42.  
  43. int a[n] = {0};
  44. int i = 0;
  45. int cur = 1;
  46. for (auto u : dp) {
  47. for (int j = 0; j < u; j++, i++) {
  48. if (i == n) i = 0;
  49. a[i] += cur;
  50. }
  51. cur *= 2;
  52. }
  53.  
  54. bool ps = 1;
  55. for (auto u : a) {
  56. if (u == 0) ps = 0;
  57. }
  58. if (!ps) {
  59. cout << -1 << "\n";
  60. continue;
  61. }
  62.  
  63. for (auto u : a) cout << u << " ";
  64. cout << "\n";
  65.  
  66.  
  67. }
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement