#include <iostream> #include <set> #include <vector> using namespace std; struct Inst { short a,b; Inst(short a, short b): a(a),b(b) { } }; inline ulong long step_forward(ulong long x, short a, short b) { // cout<<"#"<<x<<" "<<a<<" "<<b<<endl; unsigned int b1 = ( x >> a ) & 1u; if( b1 ) { unsigned int tmp = ((x>>b)&1u)^b1; return x ^ ( (tmp << a) | (tmp << b) ); } return x; } inline ulong long step_back(ulong long x, short a, short b) { return step_forward(x,b,a); } vector<Inst> M; int n,m; int solve(int k) { set<ulong long> posible; ulong long base = (1 << k) -1; for(int i = 0 ; i <= n-k ; i ++) { // cout<<">"<< (base << i)<<endl; posible.insert( base << i ); } for(int i = M.size() - 1; i >= 0 ; i --) { set<ulong long> tmp; for(auto p : posible) { ulong long k = step_back(p, M[i].a, M[i].b); if( posible.find( step_forward(k, M[i].a, M[i].b) ) != posible.end() ) { tmp.insert( k ); } if( posible.find( step_forward(p, M[i].a, M[i].b) ) != posible.end() ) { tmp.insert( p ); } } posible = tmp; } // cout<<"---"<<endl; return posible.size() % 2; } int main() { cin>>n>>m; short a,b; for(int i = 0 ; i < m ; i ++) { cin>>a>>b; a--; b--; M.emplace_back(a,b); } for(int i = 1 ; i <= n ; i ++) { cout<<solve(i)<<" "<<endl; } }
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 | #include <iostream> #include <set> #include <vector> using namespace std; struct Inst { short a,b; Inst(short a, short b): a(a),b(b) { } }; inline ulong long step_forward(ulong long x, short a, short b) { // cout<<"#"<<x<<" "<<a<<" "<<b<<endl; unsigned int b1 = ( x >> a ) & 1u; if( b1 ) { unsigned int tmp = ((x>>b)&1u)^b1; return x ^ ( (tmp << a) | (tmp << b) ); } return x; } inline ulong long step_back(ulong long x, short a, short b) { return step_forward(x,b,a); } vector<Inst> M; int n,m; int solve(int k) { set<ulong long> posible; ulong long base = (1 << k) -1; for(int i = 0 ; i <= n-k ; i ++) { // cout<<">"<< (base << i)<<endl; posible.insert( base << i ); } for(int i = M.size() - 1; i >= 0 ; i --) { set<ulong long> tmp; for(auto p : posible) { ulong long k = step_back(p, M[i].a, M[i].b); if( posible.find( step_forward(k, M[i].a, M[i].b) ) != posible.end() ) { tmp.insert( k ); } if( posible.find( step_forward(p, M[i].a, M[i].b) ) != posible.end() ) { tmp.insert( p ); } } posible = tmp; } // cout<<"---"<<endl; return posible.size() % 2; } int main() { cin>>n>>m; short a,b; for(int i = 0 ; i < m ; i ++) { cin>>a>>b; a--; b--; M.emplace_back(a,b); } for(int i = 1 ; i <= n ; i ++) { cout<<solve(i)<<" "<<endl; } } |