👉🏻 2740번: 행렬 곱셈n, m = map(int, input().split())matrix = [list(map(int, input().split())) for _ in range(n)]m, k = map(int, input().split())matrix2 = [list(map(int, input().split())) for _ in range(m)]for i in range(n): for j in range(k): result = 0 for x in range(m): result += matrix[i][x] * matrix2[x][j] print(result, end=' ') print()기본적인 행렬 곱셈 연산을 안다면 충분..
분류 전체보기
👉🏻 27961번: 고양이는 많을수록 좋다n = int(input())cat = 1cnt = 0if n == 0 or n == 1: cnt = n print(cnt)else: while cat != n: if cat >= n - cat: cat += n - cat cnt += 1 else: cat += cat cnt += 1 print(cnt + 1)단순 그리디 문제로 현재 고양이 수에 따라 while문 내에서 더하는 수를 조절하며 카운트를 늘려주기만 하면 되는 간단한 문제였습니다!
프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.krimport heapqdef solution(N, road, K): def dijkstra(): heap = [] heapq.heappush(heap, (start, 0)) costs[start] = 0 while heap: node, cost = heapq.heappop(heap) if costs[node] 전형적인 Dijkstra 알고리즘 문제입니다.구조만 외워두면 음의 간선을 포함하지 않는 가중..
👉🏻 27648번: 증가 배열 만들기n, m, k = map(int, input().split())if k >= n + m - 1: print('YES\n') for i in range(n): for j in range(m): print(f'{i+j+1} ' if i+j+1 사실 'YES', 'NO'를 판단하는 과정은 쉬운 문제입니다. k가 배열의 크기에 미치지 않을 경우에는 'NO'를 출력하면 됩니다.문제의 관건은 배열을 출력하는 데에 있는데, 이같은 경우에도 k를 넘지 않는 선에서 각 인덱스를 출력해주면 끝!
👉🏻 13413번: 오셀로 재배치for _ in range(int(input())): n = int(input()) initial = input() target = input() b_diff = sum(1 for i in range(n) if initial[i] != target[i] and initial[i] == 'B') w_diff = sum(1 for i in range(n) if initial[i] != target[i] and initial[i] == 'W') print(max(b_diff, w_diff))초기 문자열과 목표 문자열 간의 차이를 계산하고, 더 큰 차이를 나타내는 문자의 카운트를 출력하면 됩니다.이것이 가능한 이유는 두 문자의 자리를 바꿔야 하..
프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.krfrom math import gcdfrom functools import reducedef solution(arrayA, arrayB): answer = 0 mods = [] gcdA = reduce(gcd, arrayA) gcdB = reduce(gcd, arrayB) def check(gcd_value, array): for num in array: if num % gcd_value == 0: return False ..
👉🏻 30980번: 여중생 파댕이와 공부를n, m = map(int, input().split())h = 3w = 8n *= hm *= wpaper = [list(input()) for _ in range(n)]for height in range(0, n, h): for width in range(0, m, w): a = int(paper[height + 1][width + 1]) b = int(paper[height + 1][width + 3]) c = int(paper[height + 1][width + 5]) if paper[height + 1][width + 6] != '.': c = c * 10 + int(paper[..
프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.krfrom itertools import combinationsfrom collections import Counterdef solution(orders, course): answer = [] for i in course: counters = [] for order in orders: for ch in combinations(order, i): counters.append(''.join(sorted(ch))) cou..