#include <iostream> #include <vector> //#include <fstream> #define int int64_t using namespace std; const int N = 40, M = 1005; int n, m; bool res[N]; pair <int, int> sw[M]; vector <int> lev[M]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> sw[i].first >> sw[i].second; sw[i].first--; sw[i].second--; } for (int f = 0; f < n; f++) for (int l = f; l < n; l++) { int num = 0; for (int i = 0; i < n; i++) num += (int(i >= f && i <= l) << i); lev[m].push_back(num); } //int maxi = 0; for (int i = m; i > 0; --i) { //maxi = max(maxi, (int)lev[i].size()); for (auto el : lev[i]) { bool a = (el & (1LL << sw[i].first)), b = (el & (1LL << sw[i].second)); if (a == 0 || b == 1) lev[i - 1].push_back(el); if (a == 0 && b == 1) lev[i - 1].push_back(el + (1LL << sw[i].first) - (1LL << sw[i].second)); } lev[i].clear(); } //maxi = max(maxi, (int)lev[0].size()); for (auto el : lev[0]) { int c = 0; for (; el > 0; el >>= 1) c += (el & 1); res[c] = !res[c]; } for (int i = 1; i <= n; i++) cout << res[i] << ' '; /*ifstream f("a.txt"); int a = 0; f >> a; f.close(); ofstream f2("a.txt"); f2 << max(maxi, a); f2.close();*/ }
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 <iostream> #include <vector> //#include <fstream> #define int int64_t using namespace std; const int N = 40, M = 1005; int n, m; bool res[N]; pair <int, int> sw[M]; vector <int> lev[M]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> sw[i].first >> sw[i].second; sw[i].first--; sw[i].second--; } for (int f = 0; f < n; f++) for (int l = f; l < n; l++) { int num = 0; for (int i = 0; i < n; i++) num += (int(i >= f && i <= l) << i); lev[m].push_back(num); } //int maxi = 0; for (int i = m; i > 0; --i) { //maxi = max(maxi, (int)lev[i].size()); for (auto el : lev[i]) { bool a = (el & (1LL << sw[i].first)), b = (el & (1LL << sw[i].second)); if (a == 0 || b == 1) lev[i - 1].push_back(el); if (a == 0 && b == 1) lev[i - 1].push_back(el + (1LL << sw[i].first) - (1LL << sw[i].second)); } lev[i].clear(); } //maxi = max(maxi, (int)lev[0].size()); for (auto el : lev[0]) { int c = 0; for (; el > 0; el >>= 1) c += (el & 1); res[c] = !res[c]; } for (int i = 1; i <= n; i++) cout << res[i] << ' '; /*ifstream f("a.txt"); int a = 0; f >> a; f.close(); ofstream f2("a.txt"); f2 << max(maxi, a); f2.close();*/ } |