Advertisement
supremeXD

Untitled

Oct 11th, 2021
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. string ten_to_2(int val, int need_size) {
  8.     string s;
  9.     while(val > 0) {
  10.         s.push_back((val % 2) + '0');
  11.         val /= 2;
  12.     }
  13.     for(int i = (int)s.size(); i < need_size; i++) {
  14.         s.push_back('0');
  15.     }
  16.     return s;
  17. }
  18.  
  19. bool smaller2(int first, int second, int n){
  20.     string f = ten_to_2(first, n);
  21.     string s = ten_to_2(second, n);
  22.     for(int i = 0; i < n; i++) {
  23.         if(f[i] == s[i]) {
  24.             continue;
  25.         }
  26.         if(f[i] < s[i]) {
  27.             return true;
  28.         } else {
  29.             return false;
  30.         }
  31.     }
  32. }
  33.  
  34. int main() {
  35.     int n; cin >> n;
  36.     vector<int>f((1 << n));
  37.     for(int i = 0; i < (1 << n); i++) {
  38.         string s; cin >> s;
  39.         cin >> f[i];
  40.     }
  41.     vector<int>a((1 << n));
  42.     for(int i = 0; i < (1 << n); i++) {
  43.         int val = f[i];
  44.         for(int j = 0; j < i; j++) {
  45.             if(smaller2(j, i, n)) {
  46.                 val = val ^ f[j];
  47.             }
  48.         }
  49.         a[i] = val;
  50.     }
  51.     for(int i = 0; i < (1 << n); i++) {
  52.         string ans = ten_to_2(i, n);
  53.         reverse(ans.begin(), ans.end());
  54.         cout << ans << " " << a[i] << endl;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement