#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using vii = vector<pii>; vii kraw; void print_bin(ll x, int prec) { vi bits(prec); for (int i = 0; i < prec; i++) { bits[i] = x & 1; x /= 2; } for (int i = prec - 1; i >= 0; i--) { cout << bits[i]; } cout << "\n"; } inline ll swap_bits(const int& i, const int& j, const ll& x) { ll ith = x & (1LL << i); ll jth = x & (1LL << j); if (ith && !jth) { return (x & (~ith)) | (1LL << j); } return x; } int ile; const int koncz = 2e5; int backtrack(int r, ll x) { if (ile > koncz) { return 0; } if (r < 0) { ile++; return 1; } ll xs = swap_bits(kraw[r].second, kraw[r].first, x); int ans = 0; int rr = 0; if (xs != x) { ans = backtrack(r - 1, xs); rr++; } if (!(x & (1LL << kraw[r].first)) || (x & (1LL << kraw[r].second))) { ans += backtrack(r - 1, x); rr++; } if (rr == 0) { ile++; } return ans % 2; } ll newton[50][50]; int main() { ios_base::sync_with_stdio(false); cin.tie(); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; kraw.push_back({a - 1, b - 1}); } for (int i = 0; i <= n; i++) { newton[i][0] = 1; newton[i][i] = 1; } for (int i = 2; i <= n; i++) { for (int k = 1; k < i; k++) { newton[i][k] = newton[i - 1][k] + newton[i - 1][k - 1]; // cout << newton[i][k] << " "; } // cout << "\n"; } for (int i = 1; i <= n; i++) { ll ans = 0; for (int j = 0; j < n - i + 1; j++) { ll cur = 0; ile = 0; for (int k = j; k < j + i; k++) { cur |= (1LL << k); } int odp = backtrack(kraw.size() - 1, cur); if (ile > koncz) { odp = newton[n][i] % 2; } ans += odp; } cout << ans % 2 << " "; } cout << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using vii = vector<pii>; vii kraw; void print_bin(ll x, int prec) { vi bits(prec); for (int i = 0; i < prec; i++) { bits[i] = x & 1; x /= 2; } for (int i = prec - 1; i >= 0; i--) { cout << bits[i]; } cout << "\n"; } inline ll swap_bits(const int& i, const int& j, const ll& x) { ll ith = x & (1LL << i); ll jth = x & (1LL << j); if (ith && !jth) { return (x & (~ith)) | (1LL << j); } return x; } int ile; const int koncz = 2e5; int backtrack(int r, ll x) { if (ile > koncz) { return 0; } if (r < 0) { ile++; return 1; } ll xs = swap_bits(kraw[r].second, kraw[r].first, x); int ans = 0; int rr = 0; if (xs != x) { ans = backtrack(r - 1, xs); rr++; } if (!(x & (1LL << kraw[r].first)) || (x & (1LL << kraw[r].second))) { ans += backtrack(r - 1, x); rr++; } if (rr == 0) { ile++; } return ans % 2; } ll newton[50][50]; int main() { ios_base::sync_with_stdio(false); cin.tie(); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; kraw.push_back({a - 1, b - 1}); } for (int i = 0; i <= n; i++) { newton[i][0] = 1; newton[i][i] = 1; } for (int i = 2; i <= n; i++) { for (int k = 1; k < i; k++) { newton[i][k] = newton[i - 1][k] + newton[i - 1][k - 1]; // cout << newton[i][k] << " "; } // cout << "\n"; } for (int i = 1; i <= n; i++) { ll ans = 0; for (int j = 0; j < n - i + 1; j++) { ll cur = 0; ile = 0; for (int k = j; k < j + i; k++) { cur |= (1LL << k); } int odp = backtrack(kraw.size() - 1, cur); if (ile > koncz) { odp = newton[n][i] % 2; } ans += odp; } cout << ans % 2 << " "; } cout << "\n"; } |