We will find a way, we always have.

-interstellar

Problem Solving/๋ฐฑ์ค€

[๋ฐฑ์ค€] 16165๋ฒˆ: ๊ฑธ๊ทธ๋ฃน ๋งˆ์Šคํ„ฐ ์ค€์„์ด - ํŒŒ์ด์ฌ

Redddy 2022. 4. 22. 22:20

๐Ÿ“Ž๋ฌธ์ œ๋งํฌ: https://www.acmicpc.net/problem/16165

 

16165๋ฒˆ: ๊ฑธ๊ทธ๋ฃน ๋งˆ์Šคํ„ฐ ์ค€์„์ด

์ •์šฐ๋Š” ์†Œ๋ฌธ๋‚œ ๊ฑธ๊ทธ๋ฃน ๋•ํ›„์ด๋‹ค. ์ •์šฐ์˜ ์นœ๊ตฌ ์ค€์„์ด๋„ ๊ฑธ๊ทธ๋ฃน์„ ์ข‹์•„ํ•˜์ง€๋งŒ ์ด๋ฆ„์„ ์ž˜ ์™ธ์šฐ์ง€ ๋ชปํ•œ๋‹ค๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ •์šฐ๋Š” ์นœ๊ตฌ๋ฅผ ์œ„ํ•ด ๊ฑธ๊ทธ๋ฃน ๊ฐœ์ธ๊ณผ ํŒ€์˜ ์ด๋ฆ„์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ ์™ธ์šฐ๊ฒŒ ํ•˜๋Š”

www.acmicpc.net

๐ŸŽต์„œ๋ก  

๋ฌธ์ œ ์ด๋ฆ„๋ณด๊ณ  ๋Œ๋ ค์„œ ํƒํ–ˆ๋‹ค๋Š”...ใ…Žใ…Žใ…Ž
์‹ค๋ฒ„ 3 ์น˜๊ณค ์‰ฌ์šดํŽธ์ด์—ˆ๋‹ค
์ด์ƒ ์ผ€์ดํŒ ์ฒ˜๋Œ์ด

 

๐Ÿงฉ๋ฌธ์ œ ํ•ด์„

1. ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  dict() ํƒ€์ž…์œผ๋กœ ์ €์žฅํ•œ๋‹ค.
2. ์›ํ•˜๋Š” ๊ฐ’์„ dict()์˜ ๊ธฐ๋ณธ ์ œ๊ณต ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ’ป์ฝ”๋“œ

import sys
input = sys.stdin.readline

# ์ž…๋ ฅ๋ฐ›์„ ๊ฑธ๊ทธ๋ฃน์˜ ์ˆ˜์™€ ๋งžํ˜€์•ผ ํ•  ๋ฌธ์ œ ์ˆ˜๋ฅผ ๋ฐ›์Œ
n, m = map(int, input().rstrip().split())
gg_name = {}
for i in range(n):
	# ๊ฑธ๊ทธ๋ฃน ์ด๋ฆ„
    name = input().rstrip()
    gg_member = []
    for u in range(int(input().rstrip())):
        member = input().rstrip()
        # ๊ฑธ๊ทธ๋ฃน์— ๋ฉค๋ฒ„๋ฅผ ๋„ฃ๋Š”๋‹ค
        gg_member.append(member)
    # ์‚ฌ์ „์ˆœ์œผ๋กœ ์ •๋ ฌ
    gg_member.sort()
    # ๊ทธ๋ฃน ์ด๋ฆ„ : [๋ฉค๋ฒ„ ์ด๋ฆ„] ์‹์œผ๋กœ ์‚ฝ์ž…
    gg_name[name] = gg_member

for i in range(m):
    quize = input().rstrip()
    # ๋ฉค๋ฒ„๋ฅผ ๋งž์ถ”๋Š” ๊ฒฝ์šฐ, ๊ทธ๋ฃน์ด ์ฃผ์–ด์ง
    if int(input().rstrip()) == 0:
        for m in gg_name[quize]:
            print(m)
    # ๊ทธ๋ฃน์„ ๋งž์ถ”๋Š” ๊ฒฝ์šฐ, ๋ฉค๋ฒ„๊ฐ€ ์ฃผ์–ด์ง
    else:
        for a in gg_name.keys():
            if quize in gg_name[a]:
                print(a)