bingxuan9112

AAAAAAA

Feb 2nd, 2021
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define debug(args...) qqbx(#args, args)
  3. template <typename ...T> void qqbx(const char *s, T ...args) {
  4.     int cnt = sizeof...(T);
  5.     ((std::cerr << "(" << s << ") = (") , ... , (std::cerr << args << (--cnt ? ", " : ")\n")));
  6. }
  7. #define all(v) begin(v),end(v)
  8.  
  9. using namespace std;
  10. const int maxn = 2000;
  11.  
  12. int n, type;
  13. bool has[maxn];
  14. bitset<maxn> bs[maxn];
  15. bool insert(bitset<maxn> b) {
  16.     for(int i = n-1; i >= 0; i--) if(b[i]) {
  17.         if(has[i]) {
  18.             b ^= bs[i];
  19.         } else {
  20.             bs[i] = b;
  21.             has[i] = true;
  22.             return true;
  23.         }
  24.     }
  25.     return false;
  26. }
  27. int addBit(bitset<maxn> b) {
  28.     for(int i = n-1; i >= 0; i--) if(!has[i]) {
  29.         b[i] = !b[i];
  30.         assert( insert(b) );
  31.         return i;
  32.     }
  33.     abort();
  34. }
  35. signed main() {
  36.     ios_base::sync_with_stdio(0), cin.tie(0);
  37.     cin >> n >> type;
  38.     vector<bool> isBasis(n);
  39.     vector<string> ans(n);
  40.     for(int i = 0; i < n; i++) {
  41.         string s;
  42.         cin >> s;
  43.         ans[i] = s;
  44.         if(insert(bitset<maxn>(s))) {
  45.             isBasis[i] = true;
  46.         }
  47.     }
  48.     if (n == 1 && type == 2)
  49.         return cout << ans[0] << '\n', 0;
  50.     int cnt = 0;
  51.     for(int i = 0; i < n; i++) {
  52.         if(!isBasis[i]) {
  53.             int pos = addBit(bitset<maxn>(ans[i]));
  54.             ans[i][n-1-pos] ^= 1;
  55.             ++cnt;
  56.         }
  57.     }
  58.     if(type == 1)
  59.         cout << cnt << '\n';
  60.     else if(type == 2)
  61.         for(int i = 0; i < n; i++)
  62.             cout << ans[i] << '\n';
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment