π μ½λ©ν μ€νΈ λλΉ : PS
[νλ‘κ·Έλλ¨Έμ€] μ κ΅μ¬μ¬ (level3, python)
π€ νμ΄ μ½λ def check(n, times, k): can_enter = 0 for t in times: can_enter += k // t return True if can_enter >= n else False def solution(n, times): answer = 0 start = 0 end = min(times) * n mid = start while mid + 1 != end: mid = (start + end) // 2 if check(n, times, mid): end = mid else: start = mid return end π€ λ¬Έμ νμ΄ μ΄λΆνμμΌλ‘ νμ΄ν΄μΌ νλ λ¬Έμ μ λλ€. νμ μ΄λΆ νμμ μμμ κ³Ό λμ μ μ‘λ κΈ°μ€κ³Ό, μ΄λ€ κ²μ μ΄λΆνμμ μ¬μ©ν΄μΌ ν μ§ νλ¨νλκ² μ΄λ ΅λ€..
[νλ‘κ·Έλλ¨Έμ€] 거리λκΈ° νμΈνκΈ° (level2, python)
π€ νμ΄ μ½λ from collections import deque def bfs(start, place): queue = deque() queue.append([start[0], start[1], 0]) visited = [[False for _ in range(5)] for _ in range(5)] visited[start[0]][start[1]] = True dx = [0, 0, -1, 1] dy = [1, -1, 0, 0] candidate = [] while queue: a, b, dist = queue.popleft() for i in range(4): nx = dx[i] + a ny = dy[i] + b if 0
[νλ‘κ·Έλλ¨Έμ€] λ©μ©‘ν μ¬κ°ν (level2, python)
π€ νμ΄ μ½λ import math def solution(w,h): return w * h - (w + h - math.gcd(w, h)) π€ λ¬Έμ νμ΄ μ½λκ° μ§§μμ μ¬μ΄ λ¬Έμ μ²λΌ 보μ΄μ§λ§, μ μ λ° μμ΄ λμλμ§ μ΄ν΄νλ κ²μ΄ μ€μν©λλ€. λ¬Έμ μμ λμ¨ μ΄ μμλ₯Ό ν λ² λ΄ μλ€. κ°λ‘ 8, μΈλ‘ 12μ μ¬κ°νμΌλ‘, μΌμ ν ν¨ν΄μ΄ λ°λ³΅λλ κ²μ²λΌ 보μ λλ€. μμ κ°μ κ°λ‘ 2, μΈλ‘ 3μ μ¬κ°νμ ν¨ν΄μ΄ μ¬λ¬ λ² λ°λ³΅λλ κ²μ²λΌ 보μ΄μ£ . κ³μ°νλ©΄, κ°λ‘ 8 μΈλ‘ 12μ μ¬κ°νμ, κ°λ‘ 2, μΈλ‘ 3μ μ¬κ°νμμ μ μ 걸리λ μ¬κ°νμ κ°μ * 4μ λλ€. μ¬κΈ°μ 4λΌλ μ«μλ, 8κ³Ό 12μ μ΅λ 곡μ½μμΈκ²μ μ μ μμ΅λλ€. λν κ°λ‘ 2μ μΈλ‘ 3μ μλ‘μ κ΄κ³μμ μ μ μμ£ . λ°λΌμ μ΅λ 곡μ½μλ₯Ό ..
[νλ‘κ·Έλλ¨Έμ€] μ¬νκ²½λ‘ (level3, python)
π€ νμ΄ μ½λ from collections import deque import copy def bfs(start, ways, visited, n): queue = deque() queue.append([start, start, visited]) candidate = [] while queue: now, log, visit = queue.popleft() if len(log) == 4 * n - 1: candidate.append(log) continue for next in ways[now]: visited_key = now + next if visit[visited_key] != 0: visit[visited_key] -= 1 queue.append([next, log + " " + next, cop..
[νλ‘κ·Έλλ¨Έμ€] λμ€ν¬ 컨νΈλ‘€λ¬ (level3, python)
π€ νμ΄ μ½λ import heapq from collections import deque def solution(jobs): # jobs : [μμ μ΄ μμ²λλ μμ , μμ μ μμμκ°] answer = [] job_queue = deque(sorted(jobs, key=lambda x : x[0])) heap = [] time = 0 while job_queue or heap: # μμ νμμ μ€νκ°λ₯ν νμΌλ‘ μ΄λ while job_queue and job_queue[0][0]
[νλ‘κ·Έλλ¨Έμ€] μ λ ₯λ§μ λλ‘ λλκΈ° (level2, python)
π€ νμ΄ μ½λ import copy from collections import deque def bfs(start, tree, n): visited = [False for _ in range(n+1)] queue = deque() queue.append(start) visited[start] = True result = 1 while queue: now = queue.popleft() for next_node in tree[now]: if not visited[next_node]: queue.append(next_node) visited[next_node] = True result += 1 return result def solution(n, wires): answer = n adjust_arr = [[..
[νλ‘κ·Έλλ¨Έμ€] λ€μ μλ ν° μ μ°ΎκΈ° (level2, python)
π€ νμ΄ μ½λ from collections import deque def solution(numbers): answer = [-1 for i in range(len(numbers))] stack = deque() for idx, now in enumerate(numbers): if not stack: stack.append([idx, now]) continue top_idx, top_now = stack[-1] while stack and now > top_now: stack.pop() answer[top_idx] = now if stack: top_idx, top_now = stack[-1] stack.append([idx, now]) return answer π€ λ¬Έμ νμ΄ μ°μ , λ¬Έμ μ 쑰건μ 보면..
[νλ‘κ·Έλλ¨Έμ€] μ°μ λΆλΆ μμ΄ ν©μ κ°μ (level2, python)
π λ¬Έμ μ€λͺ μ² νΈλ μμ΄μ κ°μ§κ³ λκΈ° μ’μν©λλ€. μ΄λ λ μ² νΈλ μ΄λ€ μμ°μλ‘ μ΄λ£¨μ΄μ§ μν μμ΄μ μ°μνλ λΆλΆ μμ΄μ ν©μΌλ‘ λ§λ€ μ μλ μκ° λͺ¨λ λͺ κ°μ§μΈμ§ μμλ³΄κ³ μΆμ΄μ‘μ΅λλ€. μν μμ΄μ΄λ μΌλ°μ μΈ μμ΄μμ μ²μκ³Ό λμ΄ μ°κ²°λ ννμ μμ΄μ λ§ν©λλ€. μλ₯Ό λ€μ΄ μμ΄ [7, 9, 1, 1, 4] λ‘ μν μμ΄μ λ§λ€λ©΄ λ€μκ³Ό κ°μ΅λλ€. μν μμ΄μ μ²μκ³Ό λμ΄ μ°κ²°λμ΄ λκΈ°λ λΆλΆμ΄ μκΈ° λλ¬Έμ μ°μνλ λΆλΆ μμ΄λ μΌλ°μ μΈ μμ΄λ³΄λ€ λ§μμ§λλ€. μν μμ΄μ λͺ¨λ μμ elementsκ° μμλλ‘ μ£Όμ΄μ§ λ, μν μμ΄μ μ°μ λΆλΆ μμ΄ ν©μΌλ‘ λ§λ€ μ μλ μμ κ°μλ₯Ό return νλλ‘ solution ν¨μλ₯Ό μμ±ν΄μ£ΌμΈμ. μ νμ¬ν 3 ≤ elementsμ κΈΈμ΄ ≤ 1,000 1 ≤..