Help please why i have TL on #13 test
Послано
Husan 4 окт 2008 19:52
#include<iostream>
using namespace std;
struct point{
int x,y,kol;
};
int a[152][152]={{0}},val[152][152]={{0}};
int m,n;
void query(int i1,int j1,int step=5)
{
int i,j,pr[152][152]={{0}},n1;
int x1,y1;
int x[5]={0,-1,0,1,0},y[5]={0,0,1,0,-1};
point q[1000]={0},k;
i=n1=1;
q[1].x=i1;q[1].y=j1;
while(i<=n1)
{
k=q[i];
for(j=1;j<=4;j++)
{
x1=k.x+x[j];y1=k.y+y[j];
if(pr[x1][y1]==0 && k.kol<step && (x1>=1 && x1<=n && y1>=1 && y1<=m))
{
if(a[x1][y1]!=0){val[i1][j1]|=a[x1][y1];if(k.kol<step)step=k.kol+1;}
n1++;
q[n1].x=x1;
q[n1].y=y1;
q[n1].kol=k.kol+1;
pr[x1][y1]=1;
};
}
i++;
}
}
int main()
{
int i,j,k;
cin>>n>>m;
for(i=1;i<=n;i++)for(j=1;j<=m;j++){cin>>a[i][j];if(a[i][j]!=0)val[i][j]=-1;}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(a[i][j]==0)
{
query(i,j,5);
}
}
for(i=1;i<=n;i++)
{
cout<<endl;
for(j=1;j<=m;j++)cout<<val[i][j]<<" ";
}
return 0;
}