-
[백준 문제풀이] 얼렁뚱땅 7576 토마토 풀이얼렁뚱땅 백준 문제풀이 2022. 9. 6. 15:51
https://www.acmicpc.net/problem/7576
7576번: 토마토
첫 줄에는 상자의 크기를 나타내는 두 정수 M,N이 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M,N ≤ 1,000 이다. 둘째 줄부터는 하나의 상자에 저장된 토마토
www.acmicpc.net
from collections import deque import sys n, m = map(int,input().split()) arr = [list(map(int,input().split())) for i in range(m)] q = deque() for i in range(m) : for j in range(n) : if arr[i][j] == 1 : q.append([i,j,0]) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] temp_time = -1 while q : x, y, time = q.popleft() for i in range(len(dx)): nx = x + dx[i] ny = y + dy[i] if 0<=nx<m and 0<=ny<n : if arr[nx][ny] == 0 : arr[nx][ny] = 1 q.append([nx,ny,time+1]) for i in range(m) : cnt=arr[i].count(0) if cnt > 0 : print(-1) sys.exit() print(time)
기분 좋은뎁쇼
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 14891 톱니바퀴 풀이 (0) 2022.09.07 [백준 문제풀이] 얼렁뚱땅 15685 드래곤 커브 (0) 2022.09.07 [백준 문제풀이] 얼렁뚱땅 11048 이동하기 풀이 (0) 2022.09.06 [백준 문제풀이] 얼렁뚱땅 11723번 집합 풀이 (0) 2022.08.31 [백준 문제풀이] 얼렁뚱땅 20437번 문자열 게임 2 풀이 (0) 2022.08.30