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

74-tgyuuAn #242

Merged
merged 2 commits into from
Sep 20, 2024
Merged

74-tgyuuAn #242

merged 2 commits into from
Sep 20, 2024

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Aug 31, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

๋ถˆ ์ผœ๊ธฐ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

3์‹œ๊ฐ„

image image

ํ™”๋‚ฌ์ง€๋งŒ.... ํ”Œ๋ ˆ 4 ๋‹ฌ์„ฑํ–ˆ์œผ๋‹ˆ... ํ•˜ํ•˜ํ•˜ํ•˜

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

image

ํ•ต์‹ฌ : ์ง€๊ธˆ ํ˜„์žฌ ์ขŒํ‘œ์—์„œ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ ์™ธ์— ๋‚ด๊ฐ€ ๋ฐฉ๋ฌธํ–ˆ๋˜ ๊ณณ์ด๋ผ๋ฉด ๋ถˆ์ด ์ผœ์ง„ ๊ณณ์„ ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์•ผํ•จ.




์ฒซ ๋ฒˆ์งธ ์‚ฝ์งˆ : ๋งŒ์•ฝ ์ƒˆ๋กญ๊ฒŒ ๋ถˆ์ด ์ผœ์ง„๋‹ค๋ฉด visited๋ฅผ ์ดˆ๊ธฐํ™”์‹œ์ผœ์„œ ๋‹ค์‹œ ๋ชจ๋“  ์ขŒํ‘œ๋ฅผ ์žฌํƒ์ƒ‰ํ•˜๊ฒŒ ๋งŒ๋“ฌ.

-> ์‹œ๊ฐ„์ดˆ๊ณผ.




๋‘ ๋ฒˆ์งธ ์‚ฝ์งˆ : 0-1 BFS ์ฒ˜๋Ÿผ ๋‹น์žฅ ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ์ด๋ผ๋ฉด appendleft, ์ง€๊ธˆ์€ ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์—†์ง€๋งŒ ๋ถˆ์€ ์ผค ์ˆ˜ ์žˆ๋‹ค๋ฉด append๋ฅผ ํ•ด์„œ ๋‚˜์ค‘์— ์ฒดํฌ.

-> ํŠน์ • ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์—์„œ ์‹คํŒจ




๋„์›€์ด ์—„์ฒญ ๋งŽ์ด ๋œ ๋ ˆํผ๋Ÿฐ์Šค

์„ธ ๋ฒˆ์งธ : ํ˜„์žฌ ์ขŒํ‘œ์—์„œ ๋ถˆ์„ ํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๊ณณ์„ ๋ชจ๋‘ ํ‚ค๊ณ , ๋งŒ์ผ ๋‚ด๊ฐ€ ๋ฐฉ๋ฌธํ–ˆ๋˜ ๊ณณ์ด ๋ถˆ์ด ์ผœ์กŒ๋‹ค๋ฉด ํ์— ๋ฐ”๋กœ ์‚ฝ์ž….

์ดํ›„ ํ˜„์žฌ ์ขŒํ‘œ๋กœ ๋ถ€ํ„ฐ ์ƒ, ํ•˜, ์ขŒ, ์šฐ๋ฅผ ํƒ์ƒ‰ํ•ด์„œ ๋‹ฟ์„ ์ˆ˜ ์žˆ๋Š” ๊ณณ์„ ๋ชจ๋‘ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ.

์™€์šฐ!!!!!!!!!!!!!!!!!!!

ํœด,,,,,,,

image

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

@tgyuuAn tgyuuAn requested review from alstjr7437 and H0ngJu August 31, 2024 17:17
@tgyuuAn tgyuuAn self-assigned this Aug 31, 2024
@tgyuuAn tgyuuAn marked this pull request as ready for review August 31, 2024 17:25
@tgyuuAn tgyuuAn added tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ๋ฆฌ๋ทฐ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ค‘ ๐Ÿ”ฅ labels Sep 2, 2024
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

ํ—˜๋ƒ .. ๊ณ„์†๋œ ์‹œ๊ฐ„์ดˆ๊ณผ+ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค ์— ์ผ๋‹จ ํƒœ๊ทœ๋‹˜ ์ฝ”๋“œ ๋จผ์ € ์ •๋…ํ–ˆ์Šต๋‹ˆ๋‹ค.

dedicate : ๋ถˆ์„ ์ผค ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค
visited : ๋ฐฉ๋ฌธํ•œ ๋ฐฉ๋“ค
dedicate & visited = deq์— ๋„ฃ์Œ == ๋ฐฉ๋ฌธ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค

์ผ์ผ€ ์ดํ•ดํ–ˆ์–ด์š”.

๊ทผ๋ฐ ์•„์ง๋„ ์ €๋Š” ์ œ ์ฝ”๋“œ๊ฐ€ ์™œ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์”๋‹ˆ๋‹ค.?.?.?.?...
์งˆ๋ฌธ ๊ฒŒ์‹œํŒ ๋ฐ˜๋ก€๋„ ๋‹ค ํ†ต๊ณผํ•˜๋Š”๋ฐ ํ—˜,,,, ์ œ ๋ˆˆ์—๋Š” ์•ˆ๋ณดใ…‡ใ…ฃ๋„ค์š” ์ฉ...

  1. ํ˜„์žฌ ๋ฐฉ์—์„œ ์Šค์œ„์น˜๋ฅผ ์ผ ๋‹ค.
  2. ์Šค์œ„์น˜๋ฅผ ์ผ  ๋ฐฉ์ด ๋ฐฉ๋ฌธ๋…ธ๋“œ(visited)์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค
  3. ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ƒํ•˜์ขŒ์šฐ ๋…ธ๋“œ๋„ ํ™•์ธํ•œ๋‹ค -> ๋ฐฉ์— ๋ถˆ ์ผœ์ ธ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค.

ํ˜œ์•ˆ์„ ๋‚˜๋ˆ ์ฃผ์‹ค ๋ถ„์„ ์ฐพ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ˜ตโ€๐Ÿ’ซ

import sys
from collections import deque

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

N, M = map(int, input().split())
rooms = [[0] * (N) for _ in range(N)] # ๋ถˆ์ด ์ผœ์ง€๋ฉด 1
light = [ [[] for _ in range(N)] for _ in range(N)] # ์Šค์œ„์น˜ ์ •๋ณด
visited = [[False]*N for _ in range(N)] # ๋ฐฉ๋ฌธ ๋…ธ๋“œ
# lights = [list(map(int, input().split())) for _ in range(M)]

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

rooms[0][0] = 1
visited[0][0] = True

q = deque([(0,0)])
dir = [(1,0), (-1,0), (0,1), (0,-1)]

while  q:
    cx, cy = q.popleft()
    
    for nx, ny in light[cx][cy]:
        if rooms[nx][ny] == 0:
            rooms[nx][ny] = 1
            for dx, dy in dir:
                ex = cx+dx
                ey = cy+dy
                if 0<=ex<N and 0<=ey<N and visited[ex][ey]: # ์—ฐ๊ฒฐ๋œ ๋ฐฉ์ธ์ง€ ํ™•์ธํ•ด์•ผํ•จ
                    visited[nx][ny] = True
                    q.append((nx, ny))
                    break
                
    for dx, dy in dir:
        nx = cx+dx
        ny = cy+dy
        if 0<=nx<N and 0<=ny<N and rooms[nx][ny] == 1 and not visited[nx][ny]:
            visited[nx][ny] = True
            q.append((nx, ny))

print(sum(sum(r) for r in rooms))

image

@InSange
Copy link

InSange commented Sep 10, 2024

ํ—˜๋ƒ .. ๊ณ„์†๋œ ์‹œ๊ฐ„์ดˆ๊ณผ+ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค ์— ์ผ๋‹จ ํƒœ๊ทœ๋‹˜ ์ฝ”๋“œ ๋จผ์ € ์ •๋…ํ–ˆ์Šต๋‹ˆ๋‹ค.

dedicate : ๋ถˆ์„ ์ผค ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค visited : ๋ฐฉ๋ฌธํ•œ ๋ฐฉ๋“ค dedicate & visited = deq์— ๋„ฃ์Œ == ๋ฐฉ๋ฌธ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค

์ผ์ผ€ ์ดํ•ดํ–ˆ์–ด์š”.

๊ทผ๋ฐ ์•„์ง๋„ ์ €๋Š” ์ œ ์ฝ”๋“œ๊ฐ€ ์™œ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์”๋‹ˆ๋‹ค.?.?.?.?... ์งˆ๋ฌธ ๊ฒŒ์‹œํŒ ๋ฐ˜๋ก€๋„ ๋‹ค ํ†ต๊ณผํ•˜๋Š”๋ฐ ํ—˜,,,, ์ œ ๋ˆˆ์—๋Š” ์•ˆ๋ณดใ…‡ใ…ฃ๋„ค์š” ์ฉ...

  1. ํ˜„์žฌ ๋ฐฉ์—์„œ ์Šค์œ„์น˜๋ฅผ ์ผ ๋‹ค.
  2. ์Šค์œ„์น˜๋ฅผ ์ผ  ๋ฐฉ์ด ๋ฐฉ๋ฌธ๋…ธ๋“œ(visited)์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค
  3. ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ƒํ•˜์ขŒ์šฐ ๋…ธ๋“œ๋„ ํ™•์ธํ•œ๋‹ค -> ๋ฐฉ์— ๋ถˆ ์ผœ์ ธ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค.

ํ˜œ์•ˆ์„ ๋‚˜๋ˆ ์ฃผ์‹ค ๋ถ„์„ ์ฐพ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ˜ตโ€๐Ÿ’ซ

import sys
from collections import deque

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

N, M = map(int, input().split())
rooms = [[0] * (N) for _ in range(N)] # ๋ถˆ์ด ์ผœ์ง€๋ฉด 1
light = [ [[] for _ in range(N)] for _ in range(N)] # ์Šค์œ„์น˜ ์ •๋ณด
visited = [[False]*N for _ in range(N)] # ๋ฐฉ๋ฌธ ๋…ธ๋“œ
# lights = [list(map(int, input().split())) for _ in range(M)]

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

rooms[0][0] = 1
visited[0][0] = True

q = deque([(0,0)])
dir = [(1,0), (-1,0), (0,1), (0,-1)]

while  q:
    cx, cy = q.popleft()
    
    for nx, ny in light[cx][cy]:
        if rooms[nx][ny] == 0:
            rooms[nx][ny] = 1
            for dx, dy in dir:
                ex = cx+dx
                ey = cy+dy
                if 0<=ex<N and 0<=ey<N and visited[ex][ey]: # ์—ฐ๊ฒฐ๋œ ๋ฐฉ์ธ์ง€ ํ™•์ธํ•ด์•ผํ•จ
                    visited[nx][ny] = True
                    q.append((nx, ny))
                    break
                
    for dx, dy in dir:
        nx = cx+dx
        ny = cy+dy
        if 0<=nx<N and 0<=ny<N and rooms[nx][ny] == 1 and not visited[nx][ny]:
            visited[nx][ny] = True
            q.append((nx, ny))

print(sum(sum(r) for r in rooms))

image

ํ•ด๋‹น ์ฝ”๋“œ์—์„œ ex, ey๋Š” ์™œ cx, cy๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๊ณ„์‚ฐ์ด ์ง„ํ–‰๋˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”?

Copy link

@InSange InSange left a comment

Choose a reason for hiding this comment

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

์ฒ˜์Œ์— ํƒœ๊ทœ์ƒ ์™œ ์ฝ”๋“œ๋ฅผ ์ด๋ ‡๊ฒŒ ์งฐ์ง€ ํ–ˆ๋Š”๋ฐ

์•ฝ๊ฐ„ ๋ณ€ํƒœ์Šค๋Ÿฝ๊ตฐ์š”

์ˆœ์„œ๋ฅผ ๊ผฌ์•„๋†“์•˜์ง€ ํ‘ธ๋Š” ๋ฐฉ์‹์€ ๋™์ผํ•ด์„œ ๊ธˆ๋ฐฉ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๋ถˆ์„ ํ‚ค๊ณ  -> ํ˜„์žฌ ์œ„์น˜์—์„œ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ๋“ค์€ ๋‹ค ๋ฐฉ๋ฌธํ‘œ์‹œํ•ด! ๊ทผ๋ฐ ์ด๋™์€ ๋ถˆ์ผœ์ง„ ๊ณณ๋งŒ ํ• ๊บผ์•ผ(deq ์ถ”๊ฐ€) -> ๋ถˆ ์ผœ์ง„ ์ƒˆ๋กœ์šด ๊ณณ์—์„œ ๋‹ค์‹œ ๋ถˆ์„ ์ผœ๋ณธ๋‹ค. -> ๊ทผ๋ฐ ์—ฌ๊ธฐ๊ฐ€ ๋‚ด๊ฐ€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ณณ์ด๋ฉด ๋‹ค์Œ์— ์™€์•ผ์ง€ -> ๊ทธ๋ฆฌ๊ณ  ์ง€๊ธˆ ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ณณ์€ ๋‹ค ๋ฐฉ๋ฌธํ‘œ์‹œํ•ด! -> ๋ฌดํ•œ ๋ฐ˜๋ณต

์•„๋งˆ ํŒŒ์ด์ฌ ์ปดํŒŒ์ผ ์‹œ๊ฐ„์„ ๊ณ ๋ คํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ์ด๋Ÿฐ ์ฝ”๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•œ๊ฑฐ์˜€์„๊นŒ์š”?
์ฝ”๋“œ์—์„œ๋ถ€ํ„ฐ ๋‚จ๋‹ค๋ฅธ ์งฌ์ด ๋ณด์ด๋Š”๊ตฐ๋‡จ ๊ตฟ์ž…๋‹ˆ๋‹น

@tgyuuAn
Copy link
Member Author

tgyuuAn commented Sep 11, 2024

์ฒ˜์Œ์— ํƒœ๊ทœ์ƒ ์™œ ์ฝ”๋“œ๋ฅผ ์ด๋ ‡๊ฒŒ ์งฐ์ง€ ํ–ˆ๋Š”๋ฐ

์•ฝ๊ฐ„ ๋ณ€ํƒœ์Šค๋Ÿฝ๊ตฐ์š”

์ˆœ์„œ๋ฅผ ๊ผฌ์•„๋†“์•˜์ง€ ํ‘ธ๋Š” ๋ฐฉ์‹์€ ๋™์ผํ•ด์„œ ๊ธˆ๋ฐฉ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๋ถˆ์„ ํ‚ค๊ณ  -> ํ˜„์žฌ ์œ„์น˜์—์„œ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ๋“ค์€ ๋‹ค ๋ฐฉ๋ฌธํ‘œ์‹œํ•ด! ๊ทผ๋ฐ ์ด๋™์€ ๋ถˆ์ผœ์ง„ ๊ณณ๋งŒ ํ• ๊บผ์•ผ(deq ์ถ”๊ฐ€) -> ๋ถˆ ์ผœ์ง„ ์ƒˆ๋กœ์šด ๊ณณ์—์„œ ๋‹ค์‹œ ๋ถˆ์„ ์ผœ๋ณธ๋‹ค. -> ๊ทผ๋ฐ ์—ฌ๊ธฐ๊ฐ€ ๋‚ด๊ฐ€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ณณ์ด๋ฉด ๋‹ค์Œ์— ์™€์•ผ์ง€ -> ๊ทธ๋ฆฌ๊ณ  ์ง€๊ธˆ ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ณณ์€ ๋‹ค ๋ฐฉ๋ฌธํ‘œ์‹œํ•ด! -> ๋ฌดํ•œ ๋ฐ˜๋ณต

์•„๋งˆ ํŒŒ์ด์ฌ ์ปดํŒŒ์ผ ์‹œ๊ฐ„์„ ๊ณ ๋ คํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ์ด๋Ÿฐ ์ฝ”๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•œ๊ฑฐ์˜€์„๊นŒ์š”? ์ฝ”๋“œ์—์„œ๋ถ€ํ„ฐ ๋‚จ๋‹ค๋ฅธ ์งฌ์ด ๋ณด์ด๋Š”๊ตฐ๋‡จ ๊ตฟ์ž…๋‹ˆ๋‹น

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ๋ณ€ํƒœ์Šค๋Ÿฝ๋‹ค๋‡จ ,,,, ํ’€๋‹ค๋ณด๋‹ˆ ์ด๋ ‡๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… ใ… 

@InSange
Copy link

InSange commented Sep 11, 2024

์ง„์งœ ๋Œ€๋‹จํ•œ๊ฑฐ ๊ฐ™์Šด๋‹ค..
๋‹ค์‹œ ์ƒ๊ฐํ•ด๋„ ์‹ ๊ธฐํ•˜๋„ค

@H0ngJu
Copy link
Collaborator

H0ngJu commented Sep 13, 2024

ํ—˜๋ƒ .. ๊ณ„์†๋œ ์‹œ๊ฐ„์ดˆ๊ณผ+ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค ์— ์ผ๋‹จ ํƒœ๊ทœ๋‹˜ ์ฝ”๋“œ ๋จผ์ € ์ •๋…ํ–ˆ์Šต๋‹ˆ๋‹ค.
dedicate : ๋ถˆ์„ ์ผค ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค visited : ๋ฐฉ๋ฌธํ•œ ๋ฐฉ๋“ค dedicate & visited = deq์— ๋„ฃ์Œ == ๋ฐฉ๋ฌธ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋“ค
์ผ์ผ€ ์ดํ•ดํ–ˆ์–ด์š”.
๊ทผ๋ฐ ์•„์ง๋„ ์ €๋Š” ์ œ ์ฝ”๋“œ๊ฐ€ ์™œ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์”๋‹ˆ๋‹ค.?.?.?.?... ์งˆ๋ฌธ ๊ฒŒ์‹œํŒ ๋ฐ˜๋ก€๋„ ๋‹ค ํ†ต๊ณผํ•˜๋Š”๋ฐ ํ—˜,,,, ์ œ ๋ˆˆ์—๋Š” ์•ˆ๋ณดใ…‡ใ…ฃ๋„ค์š” ์ฉ...

  1. ํ˜„์žฌ ๋ฐฉ์—์„œ ์Šค์œ„์น˜๋ฅผ ์ผ ๋‹ค.
  2. ์Šค์œ„์น˜๋ฅผ ์ผ  ๋ฐฉ์ด ๋ฐฉ๋ฌธ๋…ธ๋“œ(visited)์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค
  3. ํ˜„์žฌ ์œ„์น˜์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ƒํ•˜์ขŒ์šฐ ๋…ธ๋“œ๋„ ํ™•์ธํ•œ๋‹ค -> ๋ฐฉ์— ๋ถˆ ์ผœ์ ธ์žˆ์œผ๋ฉด q์— ๋„ฃ๋Š”๋‹ค.

ํ˜œ์•ˆ์„ ๋‚˜๋ˆ ์ฃผ์‹ค ๋ถ„์„ ์ฐพ์Šต๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ˜ตโ€๐Ÿ’ซ

import sys
from collections import deque

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

N, M = map(int, input().split())
rooms = [[0] * (N) for _ in range(N)] # ๋ถˆ์ด ์ผœ์ง€๋ฉด 1
light = [ [[] for _ in range(N)] for _ in range(N)] # ์Šค์œ„์น˜ ์ •๋ณด
visited = [[False]*N for _ in range(N)] # ๋ฐฉ๋ฌธ ๋…ธ๋“œ
# lights = [list(map(int, input().split())) for _ in range(M)]

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

rooms[0][0] = 1
visited[0][0] = True

q = deque([(0,0)])
dir = [(1,0), (-1,0), (0,1), (0,-1)]

while  q:
    cx, cy = q.popleft()
    
    for nx, ny in light[cx][cy]:
        if rooms[nx][ny] == 0:
            rooms[nx][ny] = 1
            for dx, dy in dir:
                ex = cx+dx
                ey = cy+dy
                if 0<=ex<N and 0<=ey<N and visited[ex][ey]: # ์—ฐ๊ฒฐ๋œ ๋ฐฉ์ธ์ง€ ํ™•์ธํ•ด์•ผํ•จ
                    visited[nx][ny] = True
                    q.append((nx, ny))
                    break
                
    for dx, dy in dir:
        nx = cx+dx
        ny = cy+dy
        if 0<=nx<N and 0<=ny<N and rooms[nx][ny] == 1 and not visited[nx][ny]:
            visited[nx][ny] = True
            q.append((nx, ny))

print(sum(sum(r) for r in rooms))

image

ํ•ด๋‹น ์ฝ”๋“œ์—์„œ ex, ey๋Š” ์™œ cx, cy๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๊ณ„์‚ฐ์ด ์ง„ํ–‰๋˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”?

WHATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.............

๊ทธ๋Ÿฌ๋„ค์š” ... ex, ey๋Š” nx, ny ๊ธฐ์ค€์œผ๋กœ ๋‹ฌ๋ผ์ ธ์•ผํ•˜๋Š”๋ฐ cx, cy๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ด์„œ ์—…๋ฐ์ดํŠธ ํ•˜๊ณ  ์žˆ์—ˆ๋„ค์š”.............

cx -> nx
cy -> ny
๋กœ ๋ฐ”๊ฟจ๋”๋‹ˆ ํ†ต๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค ใ… ใ… ใ… 

์••๋„์  ๊ฐ์‚ฌ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ๐Ÿ™‡โ€โ™€๏ธ

image

์•„๋‹ˆ ๊ทผ๋ฐ ์งˆ๊ฒŒ ํ…Œ์ผ€ + ์˜ˆ์‹œ ํ…Œ์ผ€๊ฐ€ ๋‹ค ํ†ต๊ณผํ•œ๊ฒŒ ์ฐธ ์‹ ๊ธฐํ•˜๋„ค์š” ;;ใ…‹ใ…‹ใ…‹ใ…‹

@tgyuuAn tgyuuAn merged commit a654144 into main Sep 20, 2024
@tgyuuAn tgyuuAn deleted the 74-tgyuuAn branch September 20, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgyuuAn ํ•œ ์ค„๋กœ๋Š” ์†Œ๊ฐœํ•  ์ˆ˜ ์—†๋Š” ๋‚จ์ž. ๋ฆฌ๋ทฐ ์™„๋ฃŒ โœ”๏ธ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants