#include <iostream> #include <vector> #include <tuple> #include <functional> int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin.tie(0); int N, M; std::cin >> N >> M; std::vector<std::pair<int, int>> orders(M); for (int i = 0; i < M; i++) { std::cin >> orders[i].first >> orders[i].second; orders[i].first--; orders[i].second--; } std::vector<int> result(N+1, 0); // N <= 32 :) for(int subset = 0; subset < (1 << N); subset++) { int mask = subset; for(auto [a, b] : orders) { int A = mask & (1 << a); if(A) { int B = mask & (1 << b); mask ^= A ^ ((B >> b) << a); mask ^= B ^ ((A >> a) << b); } } int k = __builtin_popcount(mask); int segment = (1 << k) - 1; for(int i = 0; i <= N - k; i++) { if((mask & (segment << i)) == mask) { result[k] ^= 1; break; } } } for(int i = 1; i <= N; i++) { std::cout << result[i] << ' '; } std::cout << '\n'; 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 | #include <iostream> #include <vector> #include <tuple> #include <functional> int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cin.tie(0); int N, M; std::cin >> N >> M; std::vector<std::pair<int, int>> orders(M); for (int i = 0; i < M; i++) { std::cin >> orders[i].first >> orders[i].second; orders[i].first--; orders[i].second--; } std::vector<int> result(N+1, 0); // N <= 32 :) for(int subset = 0; subset < (1 << N); subset++) { int mask = subset; for(auto [a, b] : orders) { int A = mask & (1 << a); if(A) { int B = mask & (1 << b); mask ^= A ^ ((B >> b) << a); mask ^= B ^ ((A >> a) << b); } } int k = __builtin_popcount(mask); int segment = (1 << k) - 1; for(int i = 0; i <= N - k; i++) { if((mask & (segment << i)) == mask) { result[k] ^= 1; break; } } } for(int i = 1; i <= N; i++) { std::cout << result[i] << ' '; } std::cout << '\n'; return 0; } |