DevYoon

[SWEA] 5648. ์›์ž ์†Œ๋ฉธ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ๋ณธ๋ฌธ

PS/SWEA

[SWEA] 5648. ์›์ž ์†Œ๋ฉธ ์‹œ๋ฎฌ๋ ˆ์ด์…˜

gimewn 2022. 4. 10. 22:39

link ๐Ÿ”— https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRFInKex8DFAUo 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

1๏ธโƒฃ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์›์ž๊ฐ€ ์ถฉ๋Œ โžก๏ธ ์—๋„ˆ์ง€ ๋ฐฉ์ถœ & ์†Œ๋ฉธ

2๏ธโƒฃ ์ƒ ํ•˜ ์ขŒ ์šฐ ์ค‘ 1 ๋ฐฉํ–ฅ์œผ๋กœ 1์ดˆ์— 1 ์›€์ง์ž„

3๏ธโƒฃ ๋™์‹œ์— ์ด๋™

 

t = int(input())
directy = [1, -1, 0, 0]
directx = [0, 0, -1, 1]
for tc in range(1, t+1):
    N = int(input())
    arr = [list(map(int, input().split())) for _ in range(N)] # x, y, ๋ฐฉํ–ฅ, ๋ณด์œ  ์—๋„ˆ์ง€ K
    for idx in range(len(arr)):
        arr[idx][0] *= 2
        arr[idx][1] *= 2
    energy = 0
    for _ in range(4002): # -2000 ~ 2000
        for idx in range(len(arr)):
            arr[idx][0] += directx[arr[idx][2]]
            arr[idx][1] += directy[arr[idx][2]]

        ddel, visit = set(), set()
        for idx in range(len(arr)):
            nx, ny = arr[idx][0], arr[idx][1]
            if (nx, ny) in visit: # ni, nj๊ฐ€ visit์— ์žˆ์œผ๋ฉด -> DEL์— ์ถ”๊ฐ€
                ddel.add((nx, ny))
            visit.add((nx, ny))

        for idx in range(len(arr)-1, -1, -1):
            if (arr[idx][0], arr[idx][1]) in ddel:
                energy += arr[idx][3]
                arr.pop(idx)

    print(f'#{tc} {energy}')

 

โœ๏ธ ๋ฉ”๋ชจ

  • ์ฒ˜์Œ์— ๋ฐ”๋กœ ๋‹ต ๋‚˜์™€์„œ ์™€ ์›ฌ์ผ์ด์ง€? ํ–ˆ๋Š”๋ฐ ์—ญ์‹œ๋‚˜... ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ์ค‘ n๊ฐœ๋งŒ ๋งž์ท„์Šต๋‹ˆ๋‹ค...^^ ์–ด์ฉ์ง€ ์‰ฝ๋‹ค ํ–ˆ๋‹ค..๐Ÿฅฒ
  • ์ฃผ์–ด์ง„ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด -6์ธ A์™€ -3์ธ B๋Š” -4.5์—์„œ ๋ถ€๋”ชํžˆ๊ฒŒ ๋˜๋Š”๋ฐ, -4.5๋Š” ์‹ค์ˆ˜์ด๋ฏ€๋กœ ์ด๋ฅผ ์œ„ํ•ด ๊ฐ ์ขŒํ‘œ์— 2์”ฉ์„ ๊ณฑํ•ด์ฃผ์–ด ์ž์—ฐ์ˆ˜ ์ƒํƒœ์—์„œ ๋ถ€๋”ชํž ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ์–ด์•ผ ํ–ˆ๋‹ค.
  • ๋˜ ์ฃผ์–ด์ง„ ์ขŒํ‘œ ๊ฐ’์ด y, x๊ฐ€ ์•„๋‹ˆ๋ผ x, y๋ผ๋Š” ์ ...ใ…Žใ…Ž ๋ถ„๋ช… ๋งž๊ฒŒ ํ–ˆ๋Š”๋ฐ ์ž๊พธ fail ๋– ์„œ ํ•œ์ฐธ ๋“ค์—ฌ๋‹ค ๋ดค๋”๋‹ˆ ์ด๋™์‹œ์ผœ์ฃผ๋Š” ๊ณผ์ •์—์„œ x์™€ y๋ฅผ ๋ฐ”๊ฟ” ์ ์€ ๊ฒƒ์ด ์›์ธ์ด์—ˆ๋‹ค.
  • ๋ฐฐ์—ด์—์„œ๋Š” ์ƒ ํ•˜๊ฐ€ ๊ฐ๊ฐ y-1, y+1์ด์—ˆ์ง€๋งŒ ์ด ๋ฌธ์ œ์—์„œ ์ƒ ํ•˜๋Š” y+1, y-1์ด๋‹ค.