-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14502.py
53 lines (45 loc) · 1.26 KB
/
14502.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 연구소
import sys
from itertools import combinations
input = sys.stdin.readline
N, M = map(int, input().split())
ways = [[1, 0], [-1, 0], [0, 1], [0, -1]]
lab_map = []
blanks = []
first_bomb = []
for y in range(N):
line = list(input().split())
for x in range(M):
if line[x] == "0":
blanks.append([y, x])
elif line[x] == "2":
first_bomb.append([y, x])
lab_map.append(line)
comb_blank = list(combinations(blanks, 3))
max_blank = 0
for change in comb_blank:
len_blank = len(blanks)
for y, x in change:
lab_map[y][x] = "1"
len_blank -= 1
bomb = []
for bomb_y, bomb_x in first_bomb:
for i, j in ways:
bomb.append([bomb_y + i, bomb_x + j])
while bomb:
bomb_y, bomb_x = bomb.pop()
if bomb_y >= N or bomb_y < 0:
continue
if bomb_x >= M or bomb_x < 0:
continue
if lab_map[bomb_y][bomb_x] == "0":
lab_map[bomb_y][bomb_x] = "2"
len_blank -= 1
if max_blank > len_blank:
break
for i, j in ways:
bomb.append([bomb_y + i, bomb_x + j])
max_blank = max([max_blank, len_blank])
for y, x in blanks:
lab_map[y][x] = "0"
print(max_blank)