top of page

소스 코드 제출

공개·회원 50명

2025.06.04

#include <stdio.h>

int m,n,arr[1001][1001]={},day=0,cnt=0,tom=0;

int queue[2][1001]={},front=-1,back=-1,p=0;

void push(int x, int y)

{

if(x==-1||x==m+1||y==-1||y==n+1||arr[x][y]==-1)

{

return ;

}

else

{

queue[0][++back]=x;

queue[1][back]=y;

}

}

void bfs()

{

while(front!=back||front==p-1)

{

front++;

int x=queue[0][front];

int y=queue[1][front];

push(x+1,y);

push(x-1,y);

push(x,y-1);

push(x,y+1);

printf("_\n");

}

return ;

}

int main()

{

int i,j;

scanf("%d %d",&m,&n);

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&arr[i][j]);

}

}

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

if(arr[i][j]==1)

{

queue[0][++back]=i;

queue[1][back]=j;

}

}

}

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

if(arr[i][j]!=-1)

{

tom++;

}

}

}

while(1)

{

p=back;

bfs();

day++;

if(back==tom)

{

break;

}

cnt=0;

}

printf("%d",day);

return 0;

}

2회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page