Skip to content

Commit 00fb14f

Browse files
chore: sync baekjoon archives
1 parent cb0c389 commit 00fb14f

File tree

8 files changed

+365
-0
lines changed

8 files changed

+365
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def solution(N, number):
2+
buckets=[set() for _ in range(8)]
3+
for i in range(8):
4+
buckets[i].add(int(str(N)*(i+1)))
5+
for j in range(i):
6+
for b1 in buckets[j]:
7+
for b2 in buckets[i-j-1]:
8+
buckets[i].add(b1+b2)
9+
buckets[i].add(b1-b2)
10+
buckets[i].add(b1*b2)
11+
if b2!=0:
12+
buckets[i].add(b1//b2)
13+
if number in buckets[i]:
14+
return i+1
15+
return -1
16+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# [level 3] N으로 표현 - 42895
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/42895?language=python3)
4+
5+
### 성능 요약
6+
7+
메모리: 10.5 MB, 시간: 16.73 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 동적계획법(Dynamic Programming)
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 02월 18일 18:39:16
20+
21+
### 문제 설명
22+
23+
<p>아래와 같이 5와 사칙연산만으로 12를 표현할 수 있습니다.</p>
24+
25+
<p>12 = 5 + 5 + (5 / 5) + (5 / 5)<br>
26+
12 = 55 / 5 + 5 / 5<br>
27+
12 = (55 + 5) / 5</p>
28+
29+
<p>5를 사용한 횟수는 각각 6,5,4 입니다. 그리고 이중 가장 작은 경우는 4입니다.<br>
30+
이처럼 숫자 N과 number가 주어질 때, N과 사칙연산만 사용해서 표현 할 수 있는 방법 중 N 사용횟수의 최솟값을 return 하도록 solution 함수를 작성하세요.</p>
31+
32+
<h5>제한사항</h5>
33+
34+
<ul>
35+
<li>N은 1 이상 9 이하입니다.</li>
36+
<li>number는 1 이상 32,000 이하입니다.</li>
37+
<li>수식에는 괄호와 사칙연산만 가능하며 나누기 연산에서 나머지는 무시합니다.</li>
38+
<li>최솟값이 8보다 크면 -1을 return 합니다.</li>
39+
</ul>
40+
41+
<h5>입출력 예</h5>
42+
<table class="table">
43+
<thead><tr>
44+
<th>N</th>
45+
<th>number</th>
46+
<th>return</th>
47+
</tr>
48+
</thead>
49+
<tbody><tr>
50+
<td>5</td>
51+
<td>12</td>
52+
<td>4</td>
53+
</tr>
54+
<tr>
55+
<td>2</td>
56+
<td>11</td>
57+
<td>3</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
<h5>입출력 예 설명</h5>
62+
63+
<p>예제 #1<br>
64+
문제에 나온 예와 같습니다.</p>
65+
66+
<p>예제 #2<br>
67+
<code>11 = 22 / 2</code>와 같이 2를 3번만 사용하여 표현할 수 있습니다.</p>
68+
69+
<p>※ 공지 - 2020년 9월 3일 테스트케이스가 추가되었습니다.</p>
70+
71+
72+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# [level 3] 정수 삼각형 - 43105
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/43105?language=python3)
4+
5+
### 성능 요약
6+
7+
메모리: 13.8 MB, 시간: 40.98 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 동적계획법(Dynamic Programming)
12+
13+
### 채점결과
14+
15+
정확성: 64.3<br/>효율성: 35.7<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 02월 18일 19:19:45
20+
21+
### 문제 설명
22+
23+
<p><img src="https://grepp-programmers.s3.amazonaws.com/files/production/97ec02cc39/296a0863-a418-431d-9e8c-e57f7a9722ac.png" title="" alt="스크린샷 2018-09-14 오후 5.44.19.png"></p>
24+
25+
<p>위와 같은 삼각형의 꼭대기에서 바닥까지 이어지는 경로 중, 거쳐간 숫자의 합이 가장 큰 경우를 찾아보려고 합니다. 아래 칸으로 이동할 때는 대각선 방향으로 한 칸 오른쪽 또는 왼쪽으로만 이동 가능합니다. 예를 들어 3에서는 그 아래칸의 8 또는 1로만 이동이 가능합니다.</p>
26+
27+
<p>삼각형의 정보가 담긴 배열 triangle이 매개변수로 주어질 때, 거쳐간 숫자의 최댓값을 return 하도록 solution 함수를 완성하세요.</p>
28+
29+
<h5>제한사항</h5>
30+
31+
<ul>
32+
<li>삼각형의 높이는 1 이상 500 이하입니다.</li>
33+
<li>삼각형을 이루고 있는 숫자는 0 이상 9,999 이하의 정수입니다.</li>
34+
</ul>
35+
36+
<h5>입출력 예</h5>
37+
<table class="table">
38+
<thead><tr>
39+
<th>triangle</th>
40+
<th>result</th>
41+
</tr>
42+
</thead>
43+
<tbody><tr>
44+
<td>[[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]]</td>
45+
<td>30</td>
46+
</tr>
47+
</tbody>
48+
</table>
49+
50+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def solution(triangle):
2+
answer = 0
3+
n=len(triangle)
4+
for i in range(n-2,-1,-1):
5+
for j in range(len(triangle[i])):
6+
triangle[i][j]+=max(triangle[i+1][j], triangle[i+1][j+1])
7+
answer=triangle[0][0]
8+
9+
return answer
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [level 2] 점 찍기 - 140107
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/140107)
4+
5+
### 성능 요약
6+
7+
메모리: 87.4 MB, 시간: 9.75 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 연습문제
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 02월 19일 00:14:28
20+
21+
### 문제 설명
22+
23+
<p>좌표평면을 좋아하는 진수는 x축과 y축이 직교하는 2차원 좌표평면에 점을 찍으면서 놀고 있습니다. 진수는 두 양의 정수 <code>k</code>, <code>d</code>가 주어질 때 다음과 같이 점을 찍으려 합니다.</p>
24+
25+
<ul>
26+
<li>원점(0, 0)으로부터 x축 방향으로 <code>a*k</code>(a = 0, 1, 2, 3 ...), y축 방향으로 <code>b*k</code>(b = 0, 1, 2, 3 ...)만큼 떨어진 위치에 점을 찍습니다.</li>
27+
<li>원점과 거리가 <code>d</code>를 넘는 위치에는 점을 찍지 않습니다.</li>
28+
</ul>
29+
30+
<p>예를 들어, <code>k</code>가 2, <code>d</code>가 4인 경우에는 (0, 0), (0, 2), (0, 4), (2, 0), (2, 2), (4, 0) 위치에 점을 찍어 총 6개의 점을 찍습니다.</p>
31+
32+
<p>정수 <code>k</code>와 원점과의 거리를 나타내는 정수 <code>d</code>가 주어졌을 때, 점이 총 몇 개 찍히는지 return 하는 solution 함수를 완성하세요.</p>
33+
34+
<hr>
35+
36+
<h5>제한사항</h5>
37+
38+
<ul>
39+
<li>1 ≤ <code>k</code> ≤ 1,000,000</li>
40+
<li>1 ≤ <code>d</code> ≤ 1,000,000</li>
41+
</ul>
42+
43+
<hr>
44+
45+
<h5>입출력 예</h5>
46+
<table class="table">
47+
<thead><tr>
48+
<th>k</th>
49+
<th>d</th>
50+
<th>result</th>
51+
</tr>
52+
</thead>
53+
<tbody><tr>
54+
<td>2</td>
55+
<td>4</td>
56+
<td>6</td>
57+
</tr>
58+
<tr>
59+
<td>1</td>
60+
<td>5</td>
61+
<td>26</td>
62+
</tr>
63+
</tbody>
64+
</table>
65+
<hr>
66+
67+
<h5>입출력 예 설명</h5>
68+
69+
<p><strong>입출력 예 #1</strong></p>
70+
71+
<ul>
72+
<li>본문의 예시와 같습니다.</li>
73+
</ul>
74+
75+
<p><strong>입출력 예 #2</strong></p>
76+
77+
<ul>
78+
<li>(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (4, 0), (4, 1), (4, 2), (4, 3), (5, 0) 위치에 점을 찍을 수 있으며, 총 26개 입니다.</li>
79+
</ul>
80+
81+
82+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Solution {
5+
public long solution(int k, int d) {
6+
long answer = 0;
7+
for(int i=0; i<=d; i+=k) {
8+
long s = (long)d * d;
9+
long l = (long)i * i;
10+
11+
int y = (int)Math.sqrt(s-l);
12+
answer += (y/k) + 1;
13+
}
14+
return answer;
15+
}
16+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [level 2] 숫자 변환하기 - 154538
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/154538)
4+
5+
### 성능 요약
6+
7+
메모리: 97.4 MB, 시간: 53.28 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 연습문제
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 02월 18일 23:56:58
20+
21+
### 문제 설명
22+
23+
<p>자연수 <code>x</code>를 <code>y</code>로 변환하려고 합니다. 사용할 수 있는 연산은 다음과 같습니다.</p>
24+
25+
<ul>
26+
<li><code>x</code>에 <code>n</code>을 더합니다</li>
27+
<li><code>x</code>에 2를 곱합니다.</li>
28+
<li><code>x</code>에 3을 곱합니다.</li>
29+
</ul>
30+
31+
<p>자연수 <code>x</code>, <code>y</code>, <code>n</code>이 매개변수로 주어질 때, <code>x</code>를 <code>y</code>로 변환하기 위해 필요한 최소 연산 횟수를 return하도록 solution 함수를 완성해주세요. 이때 <code>x</code>를 <code>y</code>로 만들 수 없다면 -1을 return 해주세요.</p>
32+
33+
<hr>
34+
35+
<h5>제한사항</h5>
36+
37+
<ul>
38+
<li>1&nbsp;&nbsp;<code>x</code> ≤ <code>y</code>&nbsp;≤ 1,000,000</li>
39+
<li>1 ≤ <code>n</code> &lt; <code>y</code></li>
40+
</ul>
41+
42+
<hr>
43+
44+
<h5>입출력 예</h5>
45+
<table class="table">
46+
<thead><tr>
47+
<th>x</th>
48+
<th>y</th>
49+
<th>n</th>
50+
<th>result</th>
51+
</tr>
52+
</thead>
53+
<tbody><tr>
54+
<td>10</td>
55+
<td>40</td>
56+
<td>5</td>
57+
<td>2</td>
58+
</tr>
59+
<tr>
60+
<td>10</td>
61+
<td>40</td>
62+
<td>30</td>
63+
<td>1</td>
64+
</tr>
65+
<tr>
66+
<td>2</td>
67+
<td>5</td>
68+
<td>4</td>
69+
<td>-1</td>
70+
</tr>
71+
</tbody>
72+
</table>
73+
<hr>
74+
75+
<h5>입출력 예 설명</h5>
76+
77+
<p>입출력 예 #1<br>
78+
<code>x</code>에 2를 2번 곱하면 40이 되고 이때가 최소 횟수입니다.</p>
79+
80+
<p>입출력 예 #2<br>
81+
<code>x</code>에 <code>n</code>인 30을 1번 더하면 40이 되고 이때가 최소 횟수입니다.</p>
82+
83+
<p>입출력 예 #3<br>
84+
<code>x</code>를 <code>y</code>로 변환할 수 없기 때문에 -1을 return합니다.</p>
85+
86+
87+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Solution {
5+
public int solution(int x, int y, int n) {
6+
if(x == y) return 0;
7+
8+
9+
Queue<int[]> q = new ArrayDeque<>();
10+
11+
boolean[] visited = new boolean[y+1];
12+
13+
q.add(new int[]{x, 0});
14+
visited[x] = true;
15+
16+
while(!q.isEmpty()) {
17+
int[] cur = q.poll();
18+
int pos = cur[0];
19+
int count = cur[1];
20+
21+
int[] nxtPoslist = {pos+n, pos*2, pos*3};
22+
23+
for(int npl : nxtPoslist) {
24+
25+
if(npl > y || visited[npl]) continue;
26+
if(npl == y) return count+1;
27+
visited[npl] = true;
28+
q.add(new int[]{npl, count+1});
29+
}
30+
}
31+
return -1;
32+
}
33+
}

0 commit comments

Comments
 (0)