#include <algorithm> #include <vector> #include <iostream> #include <fstream> #include <bitset> #include <cstring>
using namespace std;
int N;
int C; int cur;
vector<string> lampStates = { "111111", "011011", "101010", "001110", "010101", "110001", "000000", "100100" };
vector<vector<int>> keyStates = { {0,3},{1,4},{1,2},{2,3}, {1,2},{2,3},{1,2},{2,3} }; vector<bool> on(6, false); vector<bool> off(6, false);
bool validate(int index) { for (int i = 0; i < 7; ++i) { if ((on[i] && lampStates[index][i] == '0') || (off[i] && lampStates[index][i] == '1')) { return false; } } return true; }
struct Result { string s; bool operator < (const Result& a) const { return strcmp(s.c_str(), a.s.c_str()) < 0; } } result[8];
void parseInput() { ifstream fin("lamps.in"); fin >> N; fin >> C; int cur; fin >> cur; while (cur != -1) { on[(cur - 1) % 6] = true; fin >> cur; }
fin >> cur; while (cur != - 1) { off[(cur - 1) % 6] = true; fin >> cur; } }
int main() { parseInput(); ofstream fout("lamps.out"); int count = 0; if(C < 3) { for(int i = 0; i < 8; ++i) for(int j = 0; j <= 1; ++j) { if((keyStates[i][j] == C || keyStates[i][j] == C - 2) && validate(i)) result[count++].s = lampStates[i]; } } else { for(int i = 0; i < 8; ++i) if(validate(i)) { result[count++].s = lampStates[i]; } }
if(count == 0) { fout << "IMPOSSIBLE" << endl; } else { sort(result, result + count); for(int i = 0; i < count; ++i) { int k = N; while(k >= 6) { fout << result[i].s; k -= 6; } int j = 0; while(j < k) { fout << result[i].s[j++]; } fout << endl; } } return 0; }
|