#include <bits/stdc++.h> using namespace std; vector<pair<int,int> > M; long long one=1; long long set_bits_10(long long n,int a,int b) { n = one<<a | n; n = ~(one<<b) & n; return n; } long long make_bits(int k,int p) { return ((one << k)-1) << p; } int get_bit(long long n,int p) { return (n>>p) & one; } int calc(long long bits, int move) { //cout << move << " " << bits << endl; if (move<0) return 1; int a, b; a = M[move].first-1; b = M[move].second-1; //cout << "a="<< a <<" b="<<b<<endl; if (get_bit(bits,a)==get_bit(bits,b)) return calc(bits,move-1); if (get_bit(bits,a)>get_bit(bits,b)) return 0; int s1 = calc(bits,move-1); bits = set_bits_10(bits,a,b); int s2 = calc(bits,move-1); return (s1+s2)%2; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; M.resize(m); for (int i=0;i<m;i++) { int a, b; cin >> a >> b; M[i]={a,b}; } //for (auto it=M.begin();it!=M.end();++it) cout << it->first << "," << it->second << endl; //cout << make_bits(1,34); //cout << calc(make_bits(4,0),m-1); for (int k=1;k<=n;k++) { int s = 0; for (int p=0;p<n-k+1;p++) { s = (s+calc(make_bits(k,p),m-1))%2; } cout << s << " "; } return 0; }
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 | #include <bits/stdc++.h> using namespace std; vector<pair<int,int> > M; long long one=1; long long set_bits_10(long long n,int a,int b) { n = one<<a | n; n = ~(one<<b) & n; return n; } long long make_bits(int k,int p) { return ((one << k)-1) << p; } int get_bit(long long n,int p) { return (n>>p) & one; } int calc(long long bits, int move) { //cout << move << " " << bits << endl; if (move<0) return 1; int a, b; a = M[move].first-1; b = M[move].second-1; //cout << "a="<< a <<" b="<<b<<endl; if (get_bit(bits,a)==get_bit(bits,b)) return calc(bits,move-1); if (get_bit(bits,a)>get_bit(bits,b)) return 0; int s1 = calc(bits,move-1); bits = set_bits_10(bits,a,b); int s2 = calc(bits,move-1); return (s1+s2)%2; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; M.resize(m); for (int i=0;i<m;i++) { int a, b; cin >> a >> b; M[i]={a,b}; } //for (auto it=M.begin();it!=M.end();++it) cout << it->first << "," << it->second << endl; //cout << make_bits(1,34); //cout << calc(make_bits(4,0),m-1); for (int k=1;k<=n;k++) { int s = 0; for (int p=0;p<n-k+1;p++) { s = (s+calc(make_bits(k,p),m-1))%2; } cout << s << " "; } return 0; } |