同一个开关操作两次等于不操作,那么4个开关一共16种状态,枚举,判断每种状态是都合法,有操作的都按一次算,判断总次数是否大于总操作数,然后判断奇偶性是否一致,之后按照状态得到等的对应状况即可,这里其实只用记录8中状态的值即可,因为后八种答案和前八种重复
/*
ID: jinusac1
PROG: lamps
LANG: C++
*/
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
bool is[16]={false},r[8][110]={false},s[110],b[5];
int n,op,close[110],open[110],c=0,o=0,h[]={6,7,4,5,2,3,0,1};
int order[]={6,3,4,1,7,2,5,0};
bool judge()
{
for(int i=0;i<o;i++) if(!s[open[i]])
return false;
for(int i=0;i<c;i++) if(s[close[i]])
return false;
return true;
}
void solve()
{
for(int sta=0;sta<16;sta++){
if(is[sta]) continue;
memset(b,true,sizeof(b));
int j=0,tsta=sta;
for(int k=4;k>=1;k--){
if(tsta&1){
j++;
b[k]=false;
}
tsta >>= 1;
}
if(j>op) continue;
if((j&1)!=(op&1)) continue;
is[sta]=true;
if(sta>7) sta=h[sta-8];
is[sta]=true;
memset(s,true,sizeof(s));
if(!b[1]) memset(s,false,sizeof(s));
if(!b[2]) for(int k=1;k<=n;k+=2) s[k]=!s[k];
if(!b[3]) for(int k=2;k<=n;k+=2) s[k]=!s[k];
if(!b[4]) for(int k=1;k<=n;k+=3) s[k]=!s[k];
if(judge()){
r[sta][0]=true;
for(int k=1;k<=n;k++) r[sta][k]=s[k];
}
}
}
int main()
{
freopen("lamps.in","r",stdin);
freopen("lamps.out","w",stdout);
cin>>n>>op;
int t;
while(cin>>t&&t!=-1)
open[o++]=t;
while(cin>>t&&t!=-1)
close[c++]=t;
solve();
bool mark=false;
for(int i=0;i<8;i++){
if(r[order[i]][0]){
mark=true;
for(int j=1;j<=n;j++) cout<<r[order[i]][j];
cout<<endl;
}
}
if(!mark) cout<<"IMPOSSIBLE"<<endl;
return 0;
}