728x90

몇가지 실수가 있어서 풀리지 않았었지만 이들을 해결하고 풀었다. 우선 = 을 == 이라고 적었다. 다음 wall 을 k 라고 적었었고, 깊은 복사의 의미를 잘 몰랐다. 

 

import sys
from itertools import combinations
from collections import deque
import copy
 
 
 
def bfs(temp):
 
    answer=0
 
    width = len(temp[0])
    length = len(temp)
 
    dx = [0,0,1,-1] 
    dy = [1,-1,0,0]
 
    # 2인거 queue 에 담고 돌리기
 
    queue = deque()
 
    for i in range(0,len(temp)):
        for j in range(0,len(temp[i])):
            if temp[i][j] == 2:
                queue.append([i,j])
 
    while queue:
 
        x,y = queue.popleft()
 
        for i in range(0,4):
            temp_x = x + dx[i]
            temp_y = y + dy[i]
 
            if 0<=temp_x<length and 0<=temp_y<width and temp[temp_x][temp_y]==0:
                temp[temp_x][temp_y]=2
                queue.append([temp_x,temp_y])
 
 
 
 
 
    for i in range(0,len(temp)):
        for j in range(0,len(temp[i])):
            if temp[i][j] == 0:
                answer+=1
 
    # 0의 개수 return 하기
 
    return answer
 
 
 
 
a,b = input().split(" ")
 
k = [ ]
for i in range(0,int(a)):
    k.append(list(map(int,input().split(" "))))
 
zero = [ ]
 
# 0의 위치를 리스트에 담고
 
for i in range(0,len(k)):
    for j in range(0,len(k[i])):
        if k[i][j]==0:
            zero.append([i,j])
 
# 3개를 조합을 통해 골라 벽을 세운뒤
 
wall = list(combinations(zero,3))
 
answer = [ ]
 
# 각 위치의 안전 영영의 크기를 구한다.
 
 
for i in range(0,len(wall)):    
 
    temp = copy.deepcopy(k)
 
    for j in range(0,len(wall[i])):    
 
        temp[wall[i][j][0]][wall[i][j][1]] = 1
 
    answer.append(bfs(temp))
 
 
print(max(answer))
 
 
 
 
 
 
 
728x90

+ Recent posts