목록Algorithm🔨 (52)
개발일지

A. 문제설명https://www.acmicpc.net/problem/14503 로봇 청소기가 작동을 시작한 후 작동을 멈출 때까지 청소하는 칸의 개수를 출력한다. B. 답안dir = {0:[-1,0], 1:[0,1], 2:[1,0], 3:[0,-1]}row, col = map(int,input().split())x, y, d = map(int,input().split())arr = [list(map(int, input().split())) for _ in range(row)]answer = 0while True: # 1.현재 칸 청소 if arr[x][y] == 0: arr[x][y] = 2 answer+=1 #2. 주변 청소 FULL if arr[min(x+1,row-1)][y] ..

A. 문제설명https://www.acmicpc.net/problem/14500 테트로미노가 놓인 칸에 쓰인 수들의 합의 최댓값을 출력한다. B. 답안from collections import dequefrom itertools import combinationsdx, dy = (1,0,-1,0), (0,1,0,-1)row, col = map(int,input().split())arr = [list(map(int, input().split())) for _ in range(row)]answer = 0def dfs(x, y, visited, added, depth): global answer if depth == 4: answer = max(answer, added) return for k..

A. 문제설명https://www.acmicpc.net/problem/23352 가장 긴 경로 중 시작 방과 끝 방에 적힌 숫자의 합이 가장 큰 경우를 구하라. B. 답안from collections import dequedef bfs(q, visited, start, depth): new_q = deque() while q: x,y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if row > nx >= 0 and col > ny >= 0 and arr[nx][ny] !=0 and visited[nx][ny]==0: visited[nx][ny]=1 new_q.append..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/87946 유저가 탐험할 수 있는 최대 던전 수를 return 하라. B. 답안depth = 0def solution(k, dungeons): global l l = len(dungeons) dfs(k, dungeons) return depth def dfs(k, dungeons): global depth depth = max(depth,l-len(dungeons)) for i in range(len(dungeons)): if k >= dungeons[i][0]: dfs(k-dungeons[i][1],..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/42839 종이 조각들이 주어질 때, 종이 조각으로 만들 수 있는 소수가 몇 개인지 return하라. B. 답안from collections import dequedef solution(numbers): global primes primes = set() answer = 0 arr = [int(i) for i in numbers] dfs(numbers, deque(arr), []) return len(primes)def dfs(numbers, q, num): global primes if q == []: return ..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/72412?language=python3 각 문의조건에 해당하는 사람들의 숫자를 순서대로 배열에 담아 return하라. B. 답안from itertools import productdef solution(info, query): answer = [] a= list(product(["cpp","java","python",""],["backend", "frontend",""],["junior","senior",""],["chicken", "pizza",""])) a = [''.join(i) for i in a] d = {i:[] for i in a} for ..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/150369 트럭 하나로 모든 배달과 수거를 마치고 물류창고까지 돌아올 수 있는 최소 이동 거리를 return 하라.B. 답안def solution(cap, n, d, p): answer = 0 #1. 스택 만들기 : stack 2개에 '거리x갯수' 넣기 s1, s2 = [], [] for i in range(n): s1.extend([i+1]*d[i]) s2.extend([i+1]*p[i]) #2. 거리 구하기 : tack에서 cap만큼 빼가면서 거리 구하기 while s1 or s2: answer += ..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/92342?language=python3 라이언이 가장 큰 점수 차이로 우승하기 위해 n발의 화살을 어떤 과녁 점수에 맞혀야 하는지를 10점부터 0점까지 순서대로 정수 배열에 담아 return하시오.B. 답안from itertools import productdef solution(n, info): answer = [] win_arrow = [i+1 for i in info] candidates = list(product([0,1], repeat=11)) for candidate in candidates: arrow_lion = [] s..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/42890?language=python3 릴레이션(테이블)에서 후보 키의 개수를 return하라.B. 답안from itertools import combinationsdef solution(relation): answer = 0 rows = len(relation) cols = len(relation[0]) # 1. 튜플 조합 arr = [i for i in range(cols)] possible = [combinations(arr, j) for j in range(1,cols+1)] p = [] for i in possible: ..

A. 문제설명https://school.programmers.co.kr/learn/courses/30/lessons/60057 문자열을 잘라 압축하여 표현한 문자열 중 가장 짧은 것의 길이를 return 하라.B. 답안def solution(s): l = len(s) answer = l for unit in range(1, l//2+1): count = 1 before_word = '' new_s = '' for i in range(0, l, unit): if s[i:i+unit] != before_word: if count > 1: new_s += str(c..