Skip to content

Commit 3d112cc

Browse files
authored
Kcm boj (#87)
* 찬민 백준 숙제 * 저번주 백준숙제
1 parent fc9a360 commit 3d112cc

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
n, m = map(int, input().split())
2+
3+
arr = []
4+
temp = [[0] * m for _ in range(n)]
5+
result = 0
6+
7+
dx = [-1, 1, 0, 0]
8+
dy = [0, 0, -1, 1]
9+
10+
for i in range(n):
11+
arr.append(list(map(int, input().split())))
12+
13+
14+
15+
def dfs(count):
16+
global result
17+
18+
if count == 3:
19+
for i in range(n):
20+
for j in range(m):
21+
temp[i][j] = arr[i][j]
22+
23+
for i in range(n):
24+
for j in range(m):
25+
if temp[i][j] == 2:
26+
virus(i, j)
27+
28+
result = max(result, get_score())
29+
return
30+
31+
for i in range(n):
32+
for j in range(m):
33+
if arr[i][j] == 0:
34+
arr[i][j] = 1
35+
count += 1
36+
dfs(count)
37+
arr[i][j] = 0
38+
count -= 1
39+
40+
41+
def virus(x, y):
42+
for i in range(4):
43+
nx = x + dx[i]
44+
ny = y + dy[i]
45+
if 0 <= nx < n and 0 <= ny < m:
46+
if temp[nx][ny] == 0:
47+
temp[nx][ny] = 2
48+
virus(nx, ny)
49+
50+
51+
def get_score():
52+
score = 0
53+
for i in range(n):
54+
for j in range(m):
55+
if temp[i][j] == 0:
56+
score += 1
57+
return score
58+
59+
60+
dfs(0)
61+
print(result)

0 commit comments

Comments
 (0)