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

24-alstjr7437 #187

Merged
merged 3 commits into from
May 18, 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
40 changes: 40 additions & 0 deletions alstjr7437/BFS/ํ† ๋งˆํ† .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import deque
import sys

input = sys.stdin.readline

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

n, m = map(int, input().split())
tomato = []
visited = [[0] * n for _ in range(m)]

for _ in range(m):
tomato.append(list(map(int, input().split())))

queue = deque()

for y in range(m):
for x in range(n):
if tomato[y][x] == 1:
queue.append((y,x))
visited[y][x] = 1

while queue:
y, x = queue.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx >= n or nx < 0 or ny >= m or ny < 0:
continue
if tomato[ny][nx] != -1 and visited[ny][nx] == 0:
visited[ny][nx] = 1
tomato[ny][nx] = tomato[y][x] + 1
queue.append((ny, nx))
Comment on lines +33 to +34
Copy link
Member

Choose a reason for hiding this comment

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

์˜คํ˜ธ ๋‚ ์งœ ์ •๋ณด๋ฅผ tomato ์— ๋”ํ•˜๋Š” ์‹์œผ๋กœ ์ €์žฅํ–ˆ๊ตฐ์š” ์ข‹์€๋””์š” ?????????

Copy link
Collaborator

Choose a reason for hiding this comment

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

22 ์•„ ๊ทธ๋ƒฅ ์ด์ „ tamao ์—์„œ +1 ํ•ด๋ฒ„๋ฆฌ๋ฉด ๋”ฐ๋กœ days ์ €์žฅํ•  ํ•„์š”๊ฐ€ ์—†๊ฒ ๋„ค์š” ใ„ทใ„ท

Copy link
Member Author

Choose a reason for hiding this comment

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

์ด๊ฒƒ๋„ ์ฒ˜์Œ์— max_daysํ•ด์„œ ๋„ฃ์—ˆ๋Š”๋ฐ ํ์— ๊ฐ™์ด ์ €์žฅ์„ ์•ˆํ•˜๋ฉด ๊ทธ๋ƒฅ BFS ๋Œ๋•Œ๋งˆ๋‹ค +1์ด ๋˜๋ฒ„๋ ค์„œ ์ถœ๋ ฅ์ด ์ด์ƒํ•ด์ง€๊ธธ๋ž˜ ์–ด๋–กํ•˜์ง€ ํ•˜๋‹ค๊ฐ€ ์ด๋ฐฉ๋ฒ•์œผ๋กœ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค!!!~!

Comment on lines +31 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋‚ ์งœ ์ •๋ณด๋ฅผ ํ† ๋งˆํ† ์— ๋”ํ•œ๋‹ค๋ฉด visited ์—†์ด ๊ฐ€๋Šฅํ•  ๊ฒƒ ๊ฐ™๋„ค์š”! ์–ด์ฐจํ”ผ 0์ด๋ฉด ํƒ์ƒ‰ํ•˜์ง€ ์•Š์€ ํ† ๋งˆํ† ์ผํ…Œ๋‹ˆ๊นŒ์š”~

Suggested change
if tomato[ny][nx] != -1 and visited[ny][nx] == 0:
visited[ny][nx] = 1
tomato[ny][nx] = tomato[y][x] + 1
queue.append((ny, nx))
if tomato[ny][nx] == 0:
tomato[ny][nx] = tomato[y][x] + 1
queue.append((ny, nx))


if any(0 in l for l in tomato):
print(-1)
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

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

์˜ค...................................................................... any ๋ง›์žˆ๋Š”๋ฐ์š” ...?

Copy link
Collaborator

Choose a reason for hiding this comment

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

22 ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ตณ์ด for๋ฌธ์„ ๋‘๊ฐœ ์ค‘์ฒฉํ•  ํ•„์š”๊ฐ€ ์—†๋„ค์š” ๐Ÿ‘๐Ÿ‘

Copy link
Member Author

Choose a reason for hiding this comment

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

์ €๋„ ์ฒ˜์Œ์—๋Š” ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ํ–ˆ๋‹ค๊ฐ€ ๊ทธ๋ ‡๊ฒŒ ์ฐพ์œผ๋ฉด ๋ณ€์ˆ˜๋ฅผ ํ•˜๋‚˜ ๋”๋งŒ๋“ค์–ด์•ผ ๊ฒ ๋”๋ผ๊ตฌ์š”..
๊ทธ๋ž˜์„œ any๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์จ๋ดค์Šต๋‹ˆ๋‹ค~~~~

else :
test = max(map(max, tomato))
Copy link
Collaborator

Choose a reason for hiding this comment

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

์˜คํ˜ธ๋ผ.. ์š”๋ ‡๊ฒŒ ํ•˜๋ฉด tomato์— ๋Œ€ํ•œ ์ตœ๋Œ€๊ฐ’์„ ๋ฐ”๋กœ ์ฐพ์„ ์ˆ˜ ์žˆ๊ตฐ์š”..
์ฝ”๋“œ๊ฐ€ ๊ฐ„๊ฒฐํ•ด์„œ ์ข‹๋„ค์š” ใ„ทใ„ท ๐Ÿ‘ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค (_ _)

print(test - 1)
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
| 22์ฐจ์‹œ | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |
| 21์ฐจ์‹œ | 2024.04.06 | ๋น„ํŠธ๋งˆ์Šคํ‚น | <a href="https://www.acmicpc.net/problem/11723">์ง‘ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/74 |
| 22์ฐจ์‹œ | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |
| 23์ฐจ์‹œ | 2024.05.01 | ํ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42587">ํ”„๋กœ์„ธ์Šค</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 |
| 23์ฐจ์‹œ | 2024.05.01 | ํ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42587">ํ”„๋กœ์„ธ์Šค</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 |
| 24์ฐจ์‹œ | 2024.05.14 | BFS | <a href="https://www.acmicpc.net/problem/7576">ํ† ๋งˆํ† </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/187 |
Loading