백준

import sys from collections import deque input = sys.stdin.readline n, k = map(int, input().split()) # n: 플러그 개수 usage = list(map(int, input().split())) plug = usage[:1] # 앞 두개가 모두 같은 숫자일 수 있으므로 1개만 꽂아넣기 usage = deque(usage[1:]) result = 0 while usage: i = usage.popleft() # 이미 꽂혀있을 경우 if i in plug: continue # 플러그 자리가 남았을 경우 if len(plug) < n: plug.append(i) continue # 꽂혀있는 것들 중 뽑을 것 고르기(plug inde..
import sys from collections import deque input = sys.stdin.readline q = deque() for _ in range(int(input())): command = input().rstrip() if command == "pop": print(-1 if len(q) == 0 else q.popleft()) elif command == "size": print(len(q)) elif command == "empty": print(+(not q)) elif command == "front": print(-1 if len(q) == 0 else q[0]) elif command == "back": print(-1 if len(q) == 0 else q[-1])..
import sys input = sys.stdin.readline # 팀의 수가 최소 # i번은 팀원 수가 자기 자신 포함 xi명 이하여야함 n = int(input()) xi = [0 for _ in range(n+1)] # xi의 범위는 1 O(n) 다른 사람 풀이 - 위 아이디어를 좀 더 간단하게 구현할 수 있다. xi 배열을 인원수 측정에 사용하지 않고 그냥 입력값 그대로 받아서 오름차순으로 정렬한다. 그리고 그냥 최대 인원 수 대로 끊어서 센다(간단 그잡채ㅋㅋㅋㅋ내 고민이 너무 허무해~) N = int(input()) X = list(map(int,input().split())) X.sort() i, cnt = 0, 0 while i < len(X): cnt += 1 i += X[i] prin..
import sys input = sys.stdin.readline manage = {} for _ in range(int(input())): employee, status = input().rstrip().split() if employee in manage and status == 'leave': del manage[employee] else: manage[employee] = 1 print(*sorted(manage.keys(), reverse=True), sep='\n') 해시맵, 파이썬의 딕셔너리로 풀면 간단하게 해결되는 문제다. 답을 출력할 때 포인터와 sep 파라미터를 이용하여 간단하게 출력했다. 시간 복잡도 입력받은 n만큼 로그 기록을 살펴봐야함: for문 => O(n)
빵빵0
'백준' 태그의 글 목록