๊ธฐ๋ก๋ฐฉ

BOJ_9375 : ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ ๋ณธ๋ฌธ

CodingTest/Python

BOJ_9375 : ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ

Soom_1n 2022. 9. 1. 15:06

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

9375๋ฒˆ: ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ

์ฒซ ๋ฒˆ์งธ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” headgear์— ํ•ด๋‹นํ•˜๋Š” ์˜์ƒ์ด hat, turban์ด๋ฉฐ eyewear์— ํ•ด๋‹นํ•˜๋Š” ์˜์ƒ์ด sunglasses์ด๋ฏ€๋กœ   (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)๋กœ ์ด 5๊ฐ€์ง€ ์ด๋‹ค.

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • ์˜ท ์ด๋ฆ„๊ณผ ์ข…๋ฅ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ , ์ž…์„ ์ˆ˜ ์žˆ๋Š” ์˜์ƒ ์กฐํ•ฉ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•œ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

for _ in range(int(input())):
    n = int(input())
    weardict = {}
    for _ in range(n):
        wear = list(input().split())
        if wear[1] in weardict:
            weardict[wear[1]].append(wear[0])
        else:
            weardict[wear[1]] = [wear[0]]
    cnt = 1 
    for k in weardict:
        cnt *= (len(weardict[k])+1)
    print(cnt-1)

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • ์˜์ƒ ์ข…๋ฅ˜์™€ ์ด๋ฆ„์€ ๋ฌธ์ž์—ด๋กœ ๊ฒ€์ƒ‰ํ•ด์•ผํ•˜๋ฏ€๋กœ ํ•ด์‹œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ ๋‹ค.
  • ๊ฐ™์€ ์ข…๋ฅ˜์˜ ์˜์ƒ์€ ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ค์–ด value๋กœ ์ €์žฅํ•œ๋‹ค.
  • ์กฐํ•ฉ์˜ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
    • ํ•œ ์ข…๋ฅ˜์˜ ์˜์ƒ์„ ์ž…์–ด๋„๋˜๊ณ  ์•ˆ์ž…์–ด๋„ ๋˜๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜ ๊ตฌํ•˜๊ธฐ : (์ข…๋ฅ˜ ์ˆ˜ + 1)๋ฅผ ๊ณฑํ•œ๋‹ค.
    • ๋ชจ๋‘ ์•ˆ ์ž…์€ ์ƒํƒœ๋Š” ์•ˆ๋˜๋ฏ€๋กœ ์ „์ฒด ์ˆ˜์—์„œ -1 ํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๋”•์…”๋„ˆ๋ฆฌ ์‚ฌ์šฉ๊นŒ์ง„ ๊ฐ„๋‹จํ–ˆ๋Š”๋ฐ, ์กฐํ•ฉ๋ก  ๋ถ€๋ถ„์ด ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์ฐพ์•„๋ดค๋‹ค.. ์ˆ˜ํ•™๊ณต๋ถ€๋ฅผ ๋‹ค์‹œํ•ด์•ผ ํ• ๊นŒ์‹ถ๋‹ค..

728x90

'CodingTest > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_9095 : 1, 2, 3 ๋”ํ•˜๊ธฐ  (0) 2022.09.03
BOJ_2579 : ๊ณ„๋‹จ ์˜ค๋ฅด๊ธฐ  (0) 2022.09.02
BOJ_17219 : ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ  (0) 2022.08.30
BOJ_11399 : ATM  (0) 2022.08.30
BOJ_11047 : ๋™์ „ 0  (0) 2022.08.28