-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/87946 """ # 플이 과정 def solution(k, dungeons): # 목표: 최대 던전 수 """ 일단 k가 던전 최소 피로도, 소모피로도 보다 클 시 클리어를 전제로 한 후 만약 그보다 좋은 조건의 던전이 나올 시 그것부터 클리어 한 후 다시 최종 추가는 나중에?! """ from collections import deque from itertools import permutations t = deque(list(permutations(dungeons, len(dungeons)))) result = [] dungeons.sort(key=lambda x: (x[1], -x[0])) for a in t: count = 0 p = k a = deque(list(a)) while a: c = a.popleft() if p >= c[0]: if p >= c[1]: p -= c[1] count += 1 result.append(count) return max(result)
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/59405 """ """ SELECT NAME from ANIMAL_INS order by DATETIME asc limit 1 """
-
""" 출처 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/12942 """ # 풀이 과정 def solution(matrix_sizes): m = matrix_sizes dp = [[0] * len(m) for _ in range(len(m))] l = len(m) # 자기자신은 연산값 0 for start in range(l): dp[start][0] = 0 for gap in range(1, l): for start in range(l - gap): end = start + gap result = float("inf") for go in range(start, end): result = min(dp[start][go] + dp[go + 1][end] + m[start][0] * m[go][1] * m[end][1], result) dp[start][end] = result return dp[0][l - 1]
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/42587 """ # 풀이 과정 # 숫자가 클수록 우선순위가 높다! from collections import deque def solution(priorities, location): result = 0 # 실행 순서 p = deque(priorities) l = location finish_num = p[l] p[l] = 0 while True: q = p.popleft() if q == 0: if len(p) == 0: return result + 1 else: if finish_num >= max(p): return result + 1 else: p.append(q) else: if q >= max(p) and q >= finish_num: result += 1 else: p.append(q)
-
""" 출처: 프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/59407 """ """ 풀이 과정 SELECT ANIMAL_ID from ANIMAL_INS where NAME is not null order by ANIMAL_ID asc """
-
""" 출처:프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/12938 """ # 풀이 과정 from collections import deque, defaultdict def solution(n, s): if n > s: return [-1] if s % n == 0: return [s // n] * n else: k = s % n one = [s // n + 1] * k two = [s // n] * (n - k) result = two + one return result
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/17679 """ # 풀이 과정 # idea: 첫번쨰로 지워지는 블록 제거 후 재배열 후 다시 블록 제거 반복! def solution(m, n, board): from collections import deque b = [] for k in range(m): b.append(list(board[k])) result = 0 dx = [1, 0, 1] dy = [0, 1, 1] while True: count = 0 # 지워지는 블록 체크 check = deque([]) # 지워지는 블록 목록 # i,j를 중심으로 팔방위 탐색 for i in range(m): for j in range(n): if b[i][j] == 0: continue if j - 1 >= 0 and i - 1 >= 0: if b[i][j] == b[i - 1][j - 1] == b[i][j - 1] == b[i - 1][j]: check.append([i, j]) continue if j + 1 < n and i - 1 >= 0: if b[i][j] == b[i][j + 1] == b[i - 1][j + 1] == b[i - 1][j]: check.append([i, j]) continue if j - 1 >= 0 and i + 1 < m: if b[i][j] == b[i][j - 1] == b[i + 1][j - 1] == b[i + 1][j]: check.append([i, j]) continue if j + 1 < n and i + 1 < m: if b[i][j] == b[i + 1][j] == b[i + 1][j + 1] == b[i][j + 1]: check.append([i, j]) continue while check: one, two = check.popleft() b[one][two] = 0 count += 1 if count == 0: # 지워지는 블록이 없을 경우 답 return result # 블록 재배치 위에 있는걸로 대체 # 0이 아닌 부분을 내리는 방법? for i in range(m - 1, -1, -1): for j in range(n): if b[i][j] == 0: start = i - 1 while start >= 0: if b[start][j] != 0: b[i][j] = b[start][j] b[start][j] = 0 break else: start -= 1 result += count answer = result return answer
-
""" 출처:프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/64062 """ # 풀이 과정 def solution(stones, k): max_person = max(stones) min_person = 1 result = [] while min_person <= max_person: check = (max_person + min_person) // 2 count = 0 for s in stones: if check > s: count += 1 if count >= k: break else: count = 0 else: result.append(check) min_person = check + 1 continue max_person = check - 1 return max(result)
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/17686 """ # 풀이 과정 def solution(files): f = files from collections import deque check = [] for i in f: all_new = [] # head, middle, tail 전부 들어감 # 세 부분 나누기 head = [] middle = [] tail = [] i = deque(list(i)) part = "head" while i: k = i.popleft() if k.isdigit() == False and part == "head": head.append(k) elif k.isdigit() == True and part == "head": all_new.append(list(head)) middle = [] middle.append(k) part = "middle" elif k.isdigit() == True and part == "middle": middle.append(k) elif k.isdigit() == False and part == "middle": tail.append(k) tail += list(i) all_new.append(list(middle)) all_new.append(list(tail)) break if len(tail) == 0: all_new.append(list(middle)) all_new.append([]) check.append(all_new) check.sort(key=lambda x: (("".join(x[0]).upper()), int("".join(x[1])))) final = [] for a, b, c in check: A = "".join(a) B = "".join(list(map(str, b))) C = "".join(list(map(str, c))) final.append(A + B + C) return final
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/59415 """ """ 풀이 과정 SELECT DATETIME "시간" from ANIMAL_INS order by DATETIME desc limit 1 """