[baekjoon] 7569. 토마토
코드 import collections M, N, H = map(int, input().split()) board = [[list(map(int, input().split())) for _ in range(N)] for _ in range(H)] near = [(0, -1, 0), (0, 1, 0), (1, 0, 0), (-1, 0, 0), (0, 0, 1), (0, 0, -1)] q = collections.deque() for i in range(H): for j in range(N): for k in range(M): if board[i][j][k] == 1: q.append([i, j, k, 0]) while q: x, y, z, cnt = q.popleft() for a, b, c in near..
더보기
[baekjoon] 7576. 토마토
코드 import collections N, M = map(int, input().split()) board = [list(map(int, input().split())) for _ in range(M)] near = [(0, -1), (0, 1), (1, 0), (-1, 0)] q = collections.deque() # 그냥 q로하니까 시간초과 떠서 deque로 수정 for i in range(M): for j in range(N): if board[i][j] == 1: q.append((i, j, 0)) board[i][j] = 2 while q: x, y, cnt = q.popleft() for a, b in near: xi, yi = x + a, y + b if 0 q = collection...
더보기
[programmers] 크레인 인형뽑기 게임
https://programmers.co.kr/learn/courses/30/lessons/64061 코딩테스트 연습 - 크레인 인형뽑기 게임 [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4 programmers.co.kr 로직 설명 1. board가 가로로 맨 윗줄부터 나와있는것이기 때문에 세로로 돌린다 board = [ [0,0,0,4,3], [0,0,2,2,5]. [0,1,5,4,1], [0,0,0,4,3], [0,3,1,2,1] ] 2. for i in moves: moves 돌면서 해당 board[i-1]중에 0이 아닌 첫번째값이 나오면 result 리스트에 추가하고 0으로 바꿈 - 이때, boar..
더보기