daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <vector>
  7. #include <queue>
  8. #include <set>
  9. #include <map>
  10. #include <cstdio>
  11. #include <iomanip>
  12.  
  13. #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  14. #define pb push_back
  15. #define ppb pop_back
  16. #define ft first
  17. #define sd second
  18. #define read freopen("input.txt", "r", stdin)
  19. #define write freopen("output.txt", "w", stdout)
  20. #define files read; write
  21.  
  22. using namespace std;
  23.  
  24. typedef long long ll;
  25. typedef pair<int, int> pii;
  26.  
  27. const int Z = (int)3e3 + 228;
  28. const int N = (int)3e5 + 228;
  29. const int INF = (int)1e9 + 228;
  30. const int MOD = (int)1e9 + 7;
  31.  
  32. int main()
  33. {
  34.     SWS;
  35.     //files;
  36.     int k, y;
  37.     cin >> k >> y;
  38.     vector<int> bits(30, 0);
  39.     for (int i = 0; i < 30; i++)
  40.         bits[i] = ((y >> i) & 1);
  41.     vector<int> pos0;
  42.     int cnt0;
  43.     for (int i = 0; i < 30; i++)
  44.         if (!bits[i])
  45.         {
  46.             cnt0++;
  47.             pos0.pb(i);
  48.         }
  49.     //cout << cnt0 << ' ' << pos0.size() << endl;
  50.     vector<int> ans;
  51.     for (int mask = 0; mask < (1 << cnt0); mask++)
  52.     {
  53.         if (ans.size() == k) break;
  54.         int val = 0;
  55.         for (int i = 0; i < 31; i++)
  56.             if ((mask >> i) & 1) val += (1 << pos0[i]);
  57.         val |= y;
  58.         ans.pb(val);
  59.     }
  60.     if (ans.size() != k)
  61.         cout << -1;
  62.     else
  63.         for (int i : ans)
  64.             cout << i << ' ';
  65.     return 0;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top