From 9a6e71b27b7f842d7e1b2ce96c16141108be2afe Mon Sep 17 00:00:00 2001 From: kjm3757 <111643634+kjm3757@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:30:52 +0900 Subject: [PATCH 1/5] Create 2607.py --- 2607.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 2607.py diff --git a/2607.py b/2607.py new file mode 100644 index 0000000..7c49878 --- /dev/null +++ b/2607.py @@ -0,0 +1,34 @@ +import sys +input = sys.stdin.readline + +N = int(input()) +result = 0 + +word = input() +alpa = [0]*26 + +for i in range(len(word)-1): + alpa[ord(word[i])-ord('A')] += 1 + +for _ in range(N-1): + ow = input() + oa = [0]*26 + cnt = 0 + + for i in range(len(ow)-1): + oa[ord(ow[i])-ord('A')] += 1 + + for i in range(26): + if alpa[i] != oa[i]: + cnt += abs(alpa[i] - oa[i]) + + + if len(word) == len(ow): + if cnt == 0 or cnt == 2: + result +=1 + + else: + if cnt == 1 and abs(len(word) - len(ow)) == 1: + result += 1 + +print(result) From 8fd907aa075563eca95907eefa647f482f7d818b Mon Sep 17 00:00:00 2001 From: kjm3757 <111643634+kjm3757@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:31:49 +0900 Subject: [PATCH 2/5] Create 2075.py --- 2075.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2075.py diff --git a/2075.py b/2075.py new file mode 100644 index 0000000..f1d24f2 --- /dev/null +++ b/2075.py @@ -0,0 +1,18 @@ +import heapq +import sys +input = sys.stdin.readline + +N = int(input()) +heap = [] + +for _ in range(N): + num = list(map(int, input().split())) + for n in num: + if len(heap) < N: + heapq.heappush(heap, n) + else: + if heap[0] < n: + heapq.heappop(heap) + heapq.heappush(heap, n) + +print(heap[0]) From cfba79d4ca6b8132cd88e5e616f70862b67aff3b Mon Sep 17 00:00:00 2001 From: kjm3757 <111643634+kjm3757@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:57:18 +0900 Subject: [PATCH 3/5] Create 14235.py --- 14235.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 14235.py diff --git a/14235.py b/14235.py new file mode 100644 index 0000000..8f4c95f --- /dev/null +++ b/14235.py @@ -0,0 +1,22 @@ +import heapq +import sys +input = sys.stdin.readline + +n = int(input()) + +heap = [] + +for _ in range(n): + a = list(map(int, input().split())) + + if a[0] == 0: + if len(heap) > 0: + print(-heap[0]) + heapq.heappop(heap) + + else: + print(-1) + + else: + for i in range(1, len(a)): + heapq.heappush(heap, -a[i]) From d5dcc6b6fc77ca0e47e53ca08e302fe287aee60b Mon Sep 17 00:00:00 2001 From: kjm3757 <111643634+kjm3757@users.noreply.github.com> Date: Wed, 20 Sep 2023 18:13:24 +0900 Subject: [PATCH 4/5] Create 1655.py --- 1655.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 1655.py diff --git a/1655.py b/1655.py new file mode 100644 index 0000000..8de858f --- /dev/null +++ b/1655.py @@ -0,0 +1,27 @@ +import heapq +import sys +input = sys.stdin.readline + +n = int(input()) + +lheap = [] +rheap = [] + +for i in range(n): + num = int(input()) + + if i % 2 == 0: + heapq.heappush(lheap, -num) + + else: + heapq.heappush(rheap, num) + + if i > 0: + if -lheap[0] > rheap[0]: + l = heapq.heappop(lheap) + r = heapq.heappop(rheap) + + heapq.heappush(lheap, -r) + heapq.heappush(rheap, -l) + + print("result: ", -lheap[0]) From 707bb03d7fa9ac4e6842539cc48b8007cf2f4a0f Mon Sep 17 00:00:00 2001 From: kjm3757 <111643634+kjm3757@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:41:10 +0900 Subject: [PATCH 5/5] Create programmers_disk_controller --- programmers_disk_controller | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 programmers_disk_controller diff --git a/programmers_disk_controller b/programmers_disk_controller new file mode 100644 index 0000000..77ae6a3 --- /dev/null +++ b/programmers_disk_controller @@ -0,0 +1,27 @@ +import heapq +def solution(jobs): + answer = 0 # 작업하는데 걸린 총 소요시간 + now = 0 # 현재 시간 + i = 0 # 처리한 작업의 수 + start = -1 # 직전에 완료한 작업의 시작 시간 + heap = [] # 남은 작업 중 현재 처리 가능한 작업을 저장하는 힙 + + while i < len(jobs): + # 현재 시점에서 처리할 수 있는 작업을 힙에 저장 + for j in jobs: + if start < j[0] <= now: # 작업의 요청시간이 직전에 끝낸 작업보다 크고, 현재 시간보다 작은 경우 작업이 가능힘 + heapq.heappush(heap, [j[1], j[0]]) # 작업 처리 시간, 작업 요청 시간 순으로 힙에 저장 + + if len(heap) > 0: # 힙의 길이가 0보다 큰 경우, 힙에 처리할 작업이 남은 경우 + current = heapq.heappop(heap) #current는 현재 처리 중인 작업의 정보 + start = now + now += current[0] + answer += (now - current[1]) # 작업 요청 시간부터 작업 처리 완료 시간까지 총 소요시간 + i += 1 + else: # 힙의 길이가 0인 경우, 처리할 작업이 없는 경우 + now += 1 + + answer = answer // len(jobs) # 평균 처리 시간 계산 + + return answer +