提交时间:2024-01-23 23:04:10
运行 ID: 125734
#include <bits/stdc++.h> using namespace std; int n, a[10005], x, c, str[10005]; vector<string> ans; signed main() { scanf("%d%d", &n, &c); memset(a, -1, sizeof a); while (scanf("%d", &x) && x != -1) a[x-1] = 1; while (scanf("%d", &x) && x != -1) a[x-1] = 0; for (int fir=0; fir<2; fir++) for (int sec=0; sec<2; sec++) for (int thr=0; thr<2; thr++) for (int four=0; four<2; four++) { if (fir+sec+thr+four > c) continue; if ((fir+sec+thr+four&1)!=(c&1)) continue; for (int i=0; i<n; i++) str[i] = 1; if (fir) for (int i=0; i<n; i++) str[i] ^= 1; if (thr) for (int i=1; i<n; i+=2) str[i] ^= 1; if (sec) for (int i=0; i<n; i+=2) str[i] ^= 1; if (four) for (int i=0; i<n; i+=3) str[i] ^= 1; bool flag = true; for (int i=0; i<n; i++) { if (a[i]!=-1 && str[i] != a[i]) { flag = false; break; } } if (flag) { string tmp; for (int i=0; i<n; i++) { tmp += str[i]+'0'; } ans.push_back(tmp); } } sort(ans.begin(), ans.end()); if (ans.size() == 0) puts("IMPOSSIBLE"); for (string s : ans) { printf("%s\n", s.c_str()); } return 0; }