#include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<int, int> #define us unsigned using namespace std; const int N = 35; const int K = 2000; int n, k; vec<pair<int, int>> orders; bool dp(us ll mask, int ord){ if(ord == 0) return 1; int a = orders[ord-1].f; int b = orders[ord-1].s; bool a_ = (mask >> a)&1; bool b_ = (mask >> b)&1; if(a_ == false && b_ == false) return dp(mask, ord-1); if(a_ == true && b_ == true) return dp(mask, ord-1); if(a_ == true && b_ == false) return 0; if(a_ == false && b_ == true) return dp(mask, ord-1) != dp(mask ^ ((1LL<<a)+(1LL<<b)), ord-1); } bool out[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; foru(_i, k){ int a, b; cin >> a >> b; a--; b--; orders.pb({a, b}); } foru(i, n) fors(j, n, i){ us ll mask = 0; mask = ~mask; mask = ((mask>>i)<<i) ^ ((mask>>(j+1))<<(j+1)); out[j-i] = out[j-i] ^ dp(mask, orders.size()); } foru(i, n) cout << out[i] << " "; }
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 | #include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define vec vector #define pb push_back #define f first #define s second #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define pint pair<int, int> #define us unsigned using namespace std; const int N = 35; const int K = 2000; int n, k; vec<pair<int, int>> orders; bool dp(us ll mask, int ord){ if(ord == 0) return 1; int a = orders[ord-1].f; int b = orders[ord-1].s; bool a_ = (mask >> a)&1; bool b_ = (mask >> b)&1; if(a_ == false && b_ == false) return dp(mask, ord-1); if(a_ == true && b_ == true) return dp(mask, ord-1); if(a_ == true && b_ == false) return 0; if(a_ == false && b_ == true) return dp(mask, ord-1) != dp(mask ^ ((1LL<<a)+(1LL<<b)), ord-1); } bool out[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; foru(_i, k){ int a, b; cin >> a >> b; a--; b--; orders.pb({a, b}); } foru(i, n) fors(j, n, i){ us ll mask = 0; mask = ~mask; mask = ((mask>>i)<<i) ^ ((mask>>(j+1))<<(j+1)); out[j-i] = out[j-i] ^ dp(mask, orders.size()); } foru(i, n) cout << out[i] << " "; } |