#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.h" #else #define debug(...) 2137 #endif const int N = 36; const int M = 1010; int n, m; int a[M], b[M]; ll p[N]; int ans[N]; int t[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } p[0] = 1; for (int i = 1; i <= n; i++) { p[i] = p[i - 1] * 3; } set<ll> s; s.insert(0); for (int i = 0; i < m; i++) { set<ll> ss; auto dod = [&] (ll x) { auto [it, czy] = ss.insert(x); if (!czy) { ss.erase(it); } }; for (ll v : s) { int x = (v % p[a[i] + 1]) / p[a[i]]; int y = (v % p[b[i] + 1]) / p[b[i]]; ll pa = p[a[i]]; ll pb = p[b[i]]; if (x == 1 || y == 2) { dod(v); } else if (x == 0 && y == 0) { dod(v + pa + pb); dod(v + 2 * (pa + pb)); } else if (x != 0 && y != 0) { if (x > y) { v += pb - pa; } dod(v); } else if (x == 0) { dod(v + pa - pb); } else if (y == 0) { dod(v - 2 * pa + 2 * pb); } else { assert(false); } } swap(s, ss); } for (ll v : s) { int po = 0; for (int i = 0; i < n; i++) { t[i] = v % 3; v /= 3; po += t[i] == 2; } for (int i = 0; i < n; i++) { int pp = po; for (int j = i; j < n; j++) { pp -= t[j] == 2; if (t[j] == 1) { break; } if (pp == 0) { ans[j - i + 1] ^= 1; } } if (t[i] == 2) { break; } po -= t[i] == 2; } } for (int i = 1; i <= n; i++) { cout << ans[i] << " \n"[i == 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 | #include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.h" #else #define debug(...) 2137 #endif const int N = 36; const int M = 1010; int n, m; int a[M], b[M]; ll p[N]; int ans[N]; int t[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } p[0] = 1; for (int i = 1; i <= n; i++) { p[i] = p[i - 1] * 3; } set<ll> s; s.insert(0); for (int i = 0; i < m; i++) { set<ll> ss; auto dod = [&] (ll x) { auto [it, czy] = ss.insert(x); if (!czy) { ss.erase(it); } }; for (ll v : s) { int x = (v % p[a[i] + 1]) / p[a[i]]; int y = (v % p[b[i] + 1]) / p[b[i]]; ll pa = p[a[i]]; ll pb = p[b[i]]; if (x == 1 || y == 2) { dod(v); } else if (x == 0 && y == 0) { dod(v + pa + pb); dod(v + 2 * (pa + pb)); } else if (x != 0 && y != 0) { if (x > y) { v += pb - pa; } dod(v); } else if (x == 0) { dod(v + pa - pb); } else if (y == 0) { dod(v - 2 * pa + 2 * pb); } else { assert(false); } } swap(s, ss); } for (ll v : s) { int po = 0; for (int i = 0; i < n; i++) { t[i] = v % 3; v /= 3; po += t[i] == 2; } for (int i = 0; i < n; i++) { int pp = po; for (int j = i; j < n; j++) { pp -= t[j] == 2; if (t[j] == 1) { break; } if (pp == 0) { ans[j - i + 1] ^= 1; } } if (t[i] == 2) { break; } po -= t[i] == 2; } } for (int i = 1; i <= n; i++) { cout << ans[i] << " \n"[i == n]; } } |