๐Ÿ—๏ธ Algorithm/๐ŸŸฉ ๋ฐฑ์ค€

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 15685๋ฒˆ_๋“œ๋ž˜๊ณค ์ปค๋ธŒ

Dbswnstjd 2023. 6. 26. 16:34

๋ฌธ์ œ

https://www.acmicpc.net/problem/15685

 

15685๋ฒˆ: ๋“œ๋ž˜๊ณค ์ปค๋ธŒ

์ฒซ์งธ ์ค„์— ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 20)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์˜ ์ •๋ณด๋Š” ๋„ค ์ •์ˆ˜ x, y, d, g๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. x์™€ y๋Š” ๋“œ๋ž˜๊ณค ์ปค

www.acmicpc.net

ํ’€์ด

#๋ฐฑ์ค€ 15685๋ฒˆ ๋ฌธ์ œ - ๋“œ๋ž˜๊ณค ์ปค๋ธŒ
import sys
input = sys.stdin.readline

n = int(input())

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

# ์ขŒํ‘œ๊ฐ€ ๋“œ๋ž˜๊ณค ์ปค๋ธŒ์— ํฌํ•จ์ด ๋˜๋Š”์ง€ ์ฒดํฌํ•ด์ค„ ๋ฆฌ์ŠคํŠธ
check = [[0] * (101) for _ in range(101)]

for _  in range(n):
    x,y,d,g = map(int,input().split())

    # ์ฃผ์–ด์ง„ g์„ธ๋Œ€๋™์•ˆ ์›€์ง์ธ ๋ฐฉํ–ฅ๋“ค์„ ๋‹ด์•„๋‘˜ ๋ฆฌ์ŠคํŠธ
    move_list = [d]
    # ๋จผ์ € ์‹œ์ž‘ํ•˜๋Š” x,y ์ขŒํ‘œ๋Š” ๋ฐฉ๋ฌธ์ฒดํฌ
    check[x][y] = 1
    # ์„ธ๋Œ€ ๋งŒํผ For๋ฌธ์„ ๋Œ๋ฆฌ๋ฉด์„œ
    for i in range(g):
        tmp = []
        # ์‹œ์ž‘์„ธ๋Œ€ d๋กœ ์ดˆ๊ธฐํ™”ํ•œ move_list์˜ ๊ธธ์ด๋งŒ ํผ for๋ฌธ์„ ๋Œ๋ฆฐ๋‹ค.
        # ์•ž์œผ๋กœ ๊ณ„์† ์ถ”๊ฐ€ํ•ด์ค„ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ธธ์ด๋Š” ๋Š˜์–ด๋‚œ๋‹ค.
        for j in range(len(move_list)):
            # ์ด์ „ ์„ธ๋Œ€๋“ค์„ ๋Œ๋ฉด์„œ ๋’ค์—์„œ ๋ถ€ํ„ฐ  ๋ฐฉํ–ฅ์— 1์”ฉ ๋”ํ•˜๊ณ  4๋กœ ๋‚˜๋ˆ ์„œ ๋ฐฉํ–ฅ์„ 
            # tmp์— append ์‹œํ‚จ๋‹ค.
            tmp.append((move_list[-j-1]+1)%4)
        # move_list ์— tmp๋ฅผ extend ์‹œ์ผœ์„œ ๋’ค์— ๊ทธ๋Œ€๋กœ ๋ถ™์—ฌ์ค€๋‹ค.
        move_list.extend(tmp)


    # g ์„ธ๋Œ€ ๋งŒํผ ์‹คํ–‰ํ•œ ๋’ค 
    # move_list์— ์žˆ๋Š” ๋ฐฉํ–ฅ๋“ค์„ ํ™•์ธํ•˜๋ฉด์„œ ์ขŒํ‘œ๋ฅผ ๊ณ„์‚ฐํ•ด์ฃผ๊ณ , check ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค€๋‹ค.
    for i in move_list:
        nx = x + dx[i]
        ny = y + dy[i]
        check[nx][ny] = 1 # ์ฒดํฌ์ฒ˜๋ฆฌ
        x,y = nx,ny # ๋ฐฉํ–ฅ์„ ํ˜„์žฌ ์›€์ง์ธ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐฑ์‹ 

answer = 0
# 100,100 ์ขŒํ‘œ๋ฅผ ๋Œ๋ฉด์„œ ํ•œ ์ขŒํ‘œ๊ฐ€ 1๋กœ ์ฒดํฌ๋˜์–ด์žˆ์„ ๋•Œ, 
# ๋‚˜๋จธ์ง€ ์˜ค๋ฅธ์ชฝ, ์•„๋ž˜, ์˜ค๋ฅธ์ชฝ ์•„๋ž˜๋Œ€๊ฐ์„ ์ด 1๋กœ ์ฒดํฌ๋˜์–ด์žˆ์œผ๋ฉด
# answer += 1  ์„ ํ•ด์ค€๋‹ค.
for i in range(100):
    for j in range(100):
        if check[i][j] == 1 and check[i+1][j] == 1 and check[i][j+1] == 1 and check[i+1][j+1] == 1:
            answer += 1

print(answer)

๊ทœ์น™์„ ์ฐพ๋Š”๊ฒŒ ์–ด๋ ค์› ๋˜ ๋ฌธ์ œ์ด๋‹ค. ๊ตฌํ˜„๋„ ๊ฝค ์–ด๋ ค์› ๊ณ  ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ์˜ ๋„์›€์„ ๋ฐ›์•„ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. 

 

 

์ถœ์ฒ˜

https://resilient-923.tistory.com/350