tomatobox = []
findlist = []
countday = 0
f = 0
r = 0
start = 0
xnum, ynum = map(int, input().split())
x = [-1]*(xnum+2)
tomatobox.append(x)
for i in range(ynum): # 토마토 박스 만들귀
a = []
a.append(-1)
data = list(map(int, input().split()))
for x in range(len(data)):
a.append(data[x])
a.append(-1)
tomatobox.append(a)
x = [-1]*(xnum+2)
tomatobox.append(x)
def findone(): # 숫자 1의 좌표값 찾기
global findlist
global f
findlist = []
for y in range(1, ynum+2):
for x in range(1, xnum+2):
if tomatobox[y][x] == 1:
onenum = [y, x]
findlist.append(onenum)
f += 1
def findunripe(num):
global f
print(num)
x = num[0]
y = num[1]
# print(tomatobox[x+1][y])
# print(tomatobox[x-1][y])
# print(tomatobox[x][y+1])
# print(tomatobox[x][y-1])
if (tomatobox[x+1][y] == 0):
tomatobox[x+1][y] = 1
findlist.append([x+1, y])
f += 1
if (tomatobox[x-1][y] == 0):
tomatobox[x-1][y] = 1
findlist.append([x-1, y])
f += 1
if (tomatobox[x][y+1] == 0):
tomatobox[x][y+1] = 1
findlist.append([x, y+1])
f += 1
if (tomatobox[x][y-1] == 0):
tomatobox[x][y-1] = 1
findlist.append([x, y-1])
f += 1
# def ripe():
# global countday
# global r
# global start
# global f
# start = f
# for i in range(start, f):
# countday += 1
# findunripe(i)
# findlist[r] = 0
# r = start
# print(countday-1)
def cantripe():
for y in range(1, ynum + 2):
for x in range(1, xnum + 2):
if tomatobox[y][x] == 0:
return True
isallripe = False
def allripe():
global isallripe
for y in range(1, ynum + 2):
for x in range(1, xnum + 2):
if tomatobox[y][x] == 1 or tomatobox[y][x] == -1:
isallripe = True
else:
return False
return isallripe
findone()
if allripe():
print(0)
else:
while f != r:
start = r
for i in range(start, f):
countday += 1
findunripe(findlist[r])
findlist[r] = 0
r += 1
r = start
print(tomatobox)
if cantripe():
print(-1)
else:
print(countday-1)
top of page
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
211013
211013
댓글 0개
좋아요
댓글(0)
bottom of page