Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

73-tgyuuAn #239

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tgyuuAn/BFS/Rain (Small).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from collections import deque
import sys

def input(): return sys.stdin.readline().rstrip()

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

T = int(input())

for test_idx in range(T):
row, col = map(int, input().split())
board = [list(map(int,input().split())) for _ in range(row)]
new_board = [[0 for _ in range(col)] for _ in range(row)]

for height in range(1, 1001):
for start_row in range(row):
for start_col in range(col):
if board[start_row][start_col] >= height: continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„ ์–ด์ฐจํ”ผ board ์ตœ๋Œ€- 1 ๋งŒํผ์ด height์— ๋“ค์–ด๊ฐˆ๊ฑฐ๋‹ˆ๊นŒ
๋”ฐ๋กœ max_height์„ ์„ค์ •ํ•˜๊ณ , height ์ž์ฒด๋ฅผ range(max_height)๊นŒ์ง€ ๋Œ๋ ค๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ๋ผ ๋งž์Šต๋‹ˆ๋‹ค!!!!

๊ทธ๋Ÿฌ๋ฉด ์ข€ ๋” ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค์šฉ.

๊ทผ๋ฐ WorstCase์—์„œ๋Š” ๊ฐ™์„๋“ฏ?!


deq = deque()
deq.append((start_row, start_col))
history = {(start_row, start_col),}

visited = set()
visited.add((start_row, start_col))

while deq:
now_row, now_col = deq.popleft()

# ๊ฐ€์žฅ์ž๋ฆฌ์— ๋ฌผ์ด ํ˜๋ €๋‹ค๋Š” ๊ฒƒ์ด๋ฏ€๋กœ break
if now_row in (0, row-1): break
if now_col in (0, col-1): break

for dir in range(4):
new_row = now_row + dy[dir]
new_col = now_col + dx[dir]

if new_row < 0 or new_row >= row: continue
if new_col < 0 or new_col >= col: continue
if (new_row, new_col) in visited: continue
if board[new_row][new_col] >= height: continue

deq.append((new_row, new_col))
history.add((new_row, new_col))
visited.add((new_row, new_col))

# ๊ฐ€์žฅ์ž๋ฆฌ์— ๋ฌผ์ด ํ๋ฅด์ง€ ์•Š์•„ break๋˜์ง€ ์•Š์•˜์œผ๋ฉด,
else:
for history_row, history_col in history:
new_board[history_row][history_col] = height - board[history_row][history_col]

print(f"Case #{test_idx+1}: {sum([sum(row) for row in new_board])}")
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
| 70์ฐจ์‹œ | 2024.08.16 | ์Šคํƒ | <a href="https://www.acmicpc.net/problem/22866">ํƒ‘ ๋ณด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232
| 71์ฐจ์‹œ | 2024.08.20 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/24042">๋‹ค์ต์ŠคํŠธ๋ผ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235
| 72์ฐจ์‹œ | 2024.08.23 | DFS + ํŠธ๋ฆฌ | <a href="https://www.acmicpc.net/problem/20188">๋“ฑ์‚ฐ ๋งˆ๋‹ˆ์•„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/238
| 73์ฐจ์‹œ | 2024.08.26 | BFS | <a href="https://www.acmicpc.net/problem/14324">Rain (Small)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239
---