Skip to content

Commit

Permalink
2024-06-07
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jun 7, 2024
1 parent 5aee288 commit deffa7e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
| 56차시 | 2023.05.18 | BFS | <a href="https://www.acmicpc.net/problem/17836">공주님을 구해라!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/193
| 57차시 | 2023.05.26 | 분할 정복 | <a href="https://www.acmicpc.net/problem/2263">트리의 순회</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/197
| 58차시 | 2023.05.30 | 백트래킹 | <a href="https://www.acmicpc.net/problem/1799">비숍</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/204
| 60차시 | 2023.06.07 | 그리디 | <a href="https://www.acmicpc.net/problem/14939">불 끄기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/209
---
40 changes: 40 additions & 0 deletions tgyuuAn/그리디/불 끄기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from itertools import product
from copy import deepcopy
import sys

N = 10
INF = int(1e9)
board = [list(input()) for _ in range(N)]
answer = INF

def push(board, y, x):
dx = [0, 0, 0, -1, 1]
dy = [0, -1, 1, 0, 0]

for dir in range(5):
new_y = y + dy[dir]
new_x = x + dx[dir]

if new_y < 0 or new_y >= N: continue
if new_x < 0 or new_x >= N: continue

board[new_y][new_x] = "O" if board[new_y][new_x] == "#" else "#"

for first_row_pushed in product(range(2), repeat = N):
new_board = deepcopy(board)
count = 0

for idx, pushed in enumerate(first_row_pushed):
if pushed == True:
count += 1
push(new_board, 0, idx)

for y in range(1, N):
for x in range(N):
if new_board[y-1][x] == "O":
count += 1
push(new_board, y, x)

if all(element == "#" for element in new_board[-1]): answer = min(answer, count)

print(answer if answer != INF else -1)

0 comments on commit deffa7e

Please sign in to comment.