[๋ฐฑ์ค€ ๐Ÿฅˆ4] 9017๋ฒˆ ํฌ๋กœ์Šค ์ปจํŠธ๋ฆฌ (Python/ํŒŒ์ด์ฌ)

mingssoยท2023๋…„ 3์›” 21์ผ
0

Algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
30/35

1๏ธโƒฃ ๋ฌธ์ œ

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



2๏ธโƒฃ ์ฝ”๋“œ

์ฐธ๊ฐ€์ž ์ˆ˜๊ฐ€ 6๋ช… ๋ณด๋‹ค ์ž‘์€ ํŒ€์€ ๋ฐ˜๋“œ์‹œ ์ ์ˆ˜ ๊ณ„์‚ฐ์—์„œ ์ œ์™ธํ•ด์ค˜์•ผ ์ œ๋Œ€๋กœ ๋œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜จ๋‹ค
์ด ์กฐ๊ฑด ๋ฌด์‹œํ•ด์„œ ์ฒ˜์Œ์— ํ…Œ์ผ€๋ถ€ํ„ฐ ํ‹€๋ ธ์Œ

t = int(input())
for _ in range(t):
    n = int(input())
    count = {}   # ํŒ€ ๋‹น ์ฃผ์ž ์ˆ˜
    temp = list(map(int, input().split()))
    
    # ํŒ€ ๋ณ„๋กœ ์ฃผ์ž ์ˆ˜ ์„ธ๊ธฐ
    for i in range(n):
        if temp[i] in count:
            count[temp[i]] += 1
        else:
            count[temp[i]] = 1
    
    # ์ œ์™ธ๋˜๋Š” ํŒ€ ๊ตฌํ•˜๊ธฐ
    dele = {}   # ์ œ์™ธ๋˜๋Š” ํŒ€ 
    for k, v in count.items():
        if v < 6:
            dele[k] = 1
    
    # ์ ์ˆ˜ ๊ณ„์‚ฐ
    team = {}
    idx = 1    # ์ ์ˆ˜
    for i in range(n):
        if temp[i] not in dele:
            if temp[i] in team:
                if team[temp[i]][0] < 4:
                    team[temp[i]][0] += 1
                    team[temp[i]][1] += idx
                elif team[temp[i]][0] == 4:
                    team[temp[i]][0] += 1
                    team[temp[i]][2] = idx
            else:
                team[temp[i]] = [1, idx, 0]   # [ํŒ€๋‹น ์ฃผ์ž ์ˆ˜, ์ƒ์œ„ 4๋ช… ์ ์ˆ˜ ํ•ฉ, 5๋ฒˆ์งธ ์ฃผ์ž์˜ ์ ์ˆ˜]

            idx += 1
    
    # ์ˆœ์œ„ ์ •๋ ฌ
    team = sorted(team.items(), key=lambda x:(x[1][1], x[1][2]))

๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ์ด ์ž‘์•„์„œ ๊ฑฑ์ •ํ–ˆ์ง€๋งŒ ๋ฒ”์œ„๊ฐ€ ์ž‘์•„์„œ ๊ทธ๋Ÿฐ์ง€ ๋ฌด๋ฆฌ์—†์ด ํ†ต๊ณผํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค
๊ทผ๋ฐ ์‹ค๋ฒ„4 ์ˆ˜์ค€์€ ์•„๋‹Œ ๊ฒƒ ๊ฐ™์€๋Ž…

profile
๐Ÿฅ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ’ฐ

0๊ฐœ์˜ ๋Œ“๊ธ€