[BOJ] 1700

nerry·2022년 5월 2일
0

알고리즘

목록 보기
80/86

solution

import sys
input = sys.stdin.readline

n,k = map(int,input().split())
using=list(map(int,input().split()))
taps=[]
cnt=0
for i,u in enumerate(using):
    if u in taps: continue  # 근데 안에 있다면 넘어가기
    if len(taps)!=n:
        taps.append(u)
    else:
        # 가득 찼다면
        rest = using[i:] # 멀티탭 구 수 범위 내에서
        taps_nums=[]
        for j,tap in enumerate(taps):
            if tap in rest:
                taps_nums.append([j,rest.index(tap)])
            else:
                taps_nums.append([j,k+1])
        taps_nums.sort(key=lambda x: (-x[1],x[0])) # 거리가 먼 순서대로
        taps[taps_nums[0][0]]=u
        cnt+=1
print(cnt)

원래는 얼만큼 더 나오나 해서 적게 나오는 순서대로 했다.
하지만 거리가 먼 순서대로가 맞다.

profile
터벅터벅 개발(은좋은)자 로그

0개의 댓글

Powered by GraphCDN, the GraphQL CDN