-
[13414] 수강신청 (Python)[Python] 알고리즘/Silver 2021. 11. 5. 15:01
[문제]
https://www.acmicpc.net/problem/13414
알고리즘 분류는 자료 구조, 해시를 사용한 집합과 맵 입니다.
시간 제한이 1초이므로, input() 대신 sys.stdin.readline()을 사용하고 Dictionary를 사용해야 합니다.
(List로 하면 시간초과입니다.)
[코드]
import sys K, L = map(int, sys.stdin.readline().split()) dt = dict() for i in range(L): cn = sys.stdin.readline().rstrip() dt[cn] = i dt = sorted(dt.items(), key=(lambda x: x[1])) cnt = 0 for i in dt: if cnt == K: break print(i[0]) cnt += 1 """ 이 코드로 제출하면 런타임 에러(indexError) for i in range(K): print(dt[i][0]) """
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[23056] 참가자 명단 (Python) (0) 2021.11.09 [18115] 카드 놓기 (Python) (0) 2021.11.08 [9996] 한국이 그리울 땐 서버에 접속하지 (Python) (0) 2021.11.04 [1900] 레슬러 (Python) (0) 2021.11.03 [5648] 역원소 정렬 (Python) (0) 2021.11.02