#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int>> rozkazy; int calc(long long maska, int r) { if (r == rozkazy.size()) return 1; bool a = (maska & (1LL << rozkazy[r].first)) > 0; bool b = (maska & (1LL << rozkazy[r].second)) > 0; if (a == b) return calc(maska, r + 1); if (a == 1) return 0; long long nowamaska = maska | (1LL << rozkazy[r].first); nowamaska &= ~(1LL << rozkazy[r].second); return calc(maska, r + 1) + calc(nowamaska, r + 1); } int main() { int n, m, a, b; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; rozkazy.emplace_back(a - 1, b - 1); } reverse(rozkazy.begin(), rozkazy.end()); for (int k = 1; k <= n; k++) { int wyn = 0; long long maska = (1LL << k) - 1; for (int offset = 0; offset + k <= n; offset++) { wyn += calc(maska << offset, 0); } cout << ((wyn % 2) + 2) % 2 << " "; } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int>> rozkazy; int calc(long long maska, int r) { if (r == rozkazy.size()) return 1; bool a = (maska & (1LL << rozkazy[r].first)) > 0; bool b = (maska & (1LL << rozkazy[r].second)) > 0; if (a == b) return calc(maska, r + 1); if (a == 1) return 0; long long nowamaska = maska | (1LL << rozkazy[r].first); nowamaska &= ~(1LL << rozkazy[r].second); return calc(maska, r + 1) + calc(nowamaska, r + 1); } int main() { int n, m, a, b; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; rozkazy.emplace_back(a - 1, b - 1); } reverse(rozkazy.begin(), rozkazy.end()); for (int k = 1; k <= n; k++) { int wyn = 0; long long maska = (1LL << k) - 1; for (int offset = 0; offset + k <= n; offset++) { wyn += calc(maska << offset, 0); } cout << ((wyn % 2) + 2) % 2 << " "; } return 0; } |