Skip to content

Commit

Permalink
Merge pull request #242 from AlgoLeadMe/74-tgyuuAn
Browse files Browse the repository at this point in the history
74-tgyuuAn
  • Loading branch information
tgyuuAn authored Sep 20, 2024
2 parents 825c2d2 + 53d3fe3 commit a654144
Show file tree
Hide file tree
Showing 2 changed files with 47 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 @@ -80,4 +80,5 @@
| 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
| 74์ฐจ์‹œ | 2024.08.30 | BFS | <a href="https://www.acmicpc.net/problem/11967">๋ถˆ ์ผœ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from collections import deque, defaultdict
import sys

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

N, M = map(int, input().split())
board = [[False for _ in range(N+1)] for _ in range(N+1)]
board[1][1] = True

switch = defaultdict(list)

for _ in range(M):
x, y, a, b = map(int, input().split())
switch[(x, y)].append((a,b))

deq = deque()
deq.append((1,1))
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
visited = {(1, 1),}
dedicates = {(1, 1),}

while deq:
now_x, now_y = deq.popleft()

for turn_on in switch[(now_x, now_y)]:
if turn_on not in dedicates: # <<<------- ์ด ์ฝ”๋“œ ํ•œ์ค„์— 3์‹œ๊ฐ„ ๋‚ ๋ฆผ
dedicates.add(turn_on)

if turn_on in visited:
deq.append(turn_on)

for dir in range(4):
new_x = now_x + dx[dir]
new_y = now_y + dy[dir]

if new_x <= 0 or new_x >= N+1: continue
if new_y <= 0 or new_y >= N+1: continue
if (new_x, new_y) in visited: continue

visited.add((new_x, new_y))

if (new_x, new_y) in dedicates:
deq.append((new_x, new_y))

print(len(dedicates))

0 comments on commit a654144

Please sign in to comment.