Skip to content

Commit a26e60c

Browse files
committed
1941 solve
칠공주가 가로로 나란히 있을 거라고 잘못 가정해서 많이 틀림
1 parent 49aab4e commit a26e60c

File tree

1 file changed

+31
-0
lines changed
  • 2022/[Week27 - Mix]/송민기

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from itertools import combinations
2+
from collections import deque
3+
4+
grid = [input().rstrip() for _ in range(5)]
5+
arr = [(r, c) for r in range(5) for c in range(5)]
6+
comb = list(combinations(arr, 7)) # 480700
7+
dRow, dCol = [0, 0, 1, -1], [1, -1, 0, 0]
8+
9+
answer = 0
10+
for _comb in comb:
11+
cnt_s = 0
12+
for r, c in _comb:
13+
if grid[r][c] == 'S':
14+
cnt_s += 1
15+
if cnt_s < 4:
16+
continue
17+
r, c = _comb[0]
18+
q = deque()
19+
q.append((r, c))
20+
visited = set()
21+
visited.add((r, c))
22+
while q:
23+
_r, _c = q.popleft()
24+
for d in range(4):
25+
nr, nc = _r + dRow[d], _c + dCol[d]
26+
if (nr, nc) in _comb and (nr, nc) not in visited:
27+
q.append((nr, nc))
28+
visited.add((nr, nc))
29+
if len(visited) == 7:
30+
answer += 1
31+
print(answer)

0 commit comments

Comments
 (0)