코테 공부
백준[1700] 멀티탭 스케줄링 (파이썬 풀이)
moonsun623
2021. 10. 7. 15:57
반응형
https://www.acmicpc.net/problem/1700
1700번: 멀티탭 스케줄링
기숙사에서 살고 있는 준규는 한 개의 멀티탭을 이용하고 있다. 준규는 키보드, 헤어드라이기, 핸드폰 충전기, 디지털 카메라 충전기 등 여러 개의 전기용품을 사용하면서 어쩔 수 없이 각종 전
www.acmicpc.net
내가 한 풀이
이 문제는 두 가지 경우로 크게 나눌 수 있다.
교체가 필요 없는 경우 1) 이미 해당 가전제품이 멀티탭에 꽂혀있는 경우
2) 멀티탭이 빈경우 -> 빈 곳에 가전제품 꽂으면 됨
교체가 필요한 경우에는 현재 멀티탭에 꽂힌 제품들이 이후에 사용되는지, 더 빨리 사용되는지 체크해야한다.
n,k=map(int,input().split(" "))
pattern=list(map(int,input().split(" ")))
outlet=[]
cnt=0
for i in range(k):
if pattern[i] in outlet:
continue
if len(outlet)<n:
outlet.append(pattern[i])
continue
cnt+=1
index=0
remove=0
for j in range(n):
try:
tmp=pattern[i+1:].index(outlet[j])
if tmp>index:
remove=j
index=tmp
except:
remove=j
break
outlet[remove]=pattern[i]
print(cnt)