代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int on[1100],s=0,ans[1100][110],ys[110];
int n,c;
inline long long read()
{
long long x=0,w=0;char ch=getchar();
while(ch<'0'||ch>'9')w|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return w?-x:x;
}
bool check(bool d1,bool d2,bool d3,bool d4)
{
for(int i=1;i<=n;i++) ys[i]=1;
if(d1) for(register int i=1;i<=n;++i) ys[i]=1-ys[i];
if(d2) for(register int i=1;i<=n;i+=2) ys[i]=1-ys[i];
if(d3) for(register int i=2;i<=n;i+=2) ys[i]=1-ys[i];
if(d4) for(register int i=1;i<=n;i+=3) ys[i]=1-ys[i];
for(register int i=1;i<=n;++i)
{
if(on[i]==2) continue;
else if(ys[i]!=on[i]) return 0;
}
return 1;
}
int main()
{
n=read(),c=read();
for(register int i=1;i<=n;++i) on[i]=2;
while(1)
{
int x=read();
if(x==-1) break;
on[x]=1;
}
while(1)
{
int x=read();
if(x==-1) break;
on[x]=0;
}
for(register int d1=0;d1<=1;++d1)
{
for(register int d2=0;d2<=1;++d2)
{
for(register int d3=0;d3<=1;++d3)
{
for(register int d4=0;d4<=1;++d4)
{
int ti=d1+d2+d3+d4;
if(ti>c) continue;
if(check(d1,d2,d3,d4)&&(c-ti)%2==0)
{
++s;
for(register int i=1;i<=n;++i) ans[s][i]=ys[i];
}
}
}
}
}
if(s==0) printf("IMPOSSIBLE\n");
for(register int i=1;i<=s;++i)
{
for(register int j=i+1;j<=s;++j)
{
for(register int k=1;k<=n;++k)
{
if(ans[i][k]>ans[j][k]) {swap(ans[i],ans[j]);break;}
else if(ans[i][k]<ans[j][k]) break;
}
}
}
for(register int i=1;i<=s;++i)
{
for(register int j=1;j<=n;++j) printf("%d",ans[i][j]);
printf("\n");
}
return 0;
}