Skip to content

Commit 9137269

Browse files
authored
Merge branch 'main' into minjeong3
2 parents b5442a4 + 4f2a61a commit 9137269

10 files changed

+274
-57
lines changed

β€Ž.github/workflows/update_challenge_progress.ymlβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ jobs:
3737
cd _MonthlyChallenges
3838
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
3939
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
40+
git pull origin main
4041
git add scoreboard.json DASHBOARD.md HISTORY.md
4142
git commit -m "Update challenge progress dashboard" || echo "No changes to commit"
42-
cd ..
43-
git remote set-url origin https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study.git
4443
git push origin ${{ github.head_ref }}
4544
4645
- name: Post PR Comment with progress

β€ŽHongjoo/λ°±μ€€/λ‘œλ΄‡μ‘°μ’…ν•˜κΈ°.pyβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
for n in range(N) :
1111
fields.append(list(map(int, input().split())))
1212

13-
# print(fields)
1413
# 2. dp ν…Œμ΄λΈ” μ΄ˆκΈ°ν™”
1514
dp = [[0 for _ in range(M)] for k in range(N)]
1615
left2right = [[0 for _ in range(M)] for k in range(N)]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
# slide window , 투 포인터
3+
-μ—°μ†λœ λ‚ μ§œμ˜ μ˜¨λ„ ν•© 쀑 μ΅œλŒ€κ°’ 좜λ ₯ = goal
4+
- sum(temp[s:e]) 같은 ν•œλ²ˆμ”© μŠ¬λΌμ΄λ”©μœΌλ‘œ 합을 κ΅¬ν•˜λ©΄ μ‹œκ°„ 초과 λ°œμƒ
5+
- window λ²”μœ„ λ‚΄ start 와 end 포인트 값을 λΉΌκ³ , λ”ν•˜λŠ” μ‹μœΌλ‘œ 전체 ν•© κ΅¬ν•˜κΈ°
6+
# flow
7+
1. temp 리슀트 μž…λ ₯ λ°›κΈ°
8+
-window size =k , N : λ‚ μ§œ
9+
2. window λ²”μœ„μ— ν•΄λ‹Ήν•˜λŠ” 리슀트 ν•© 쀑 μ΅œλŒ€κ°’ κ΅¬ν•˜κΈ°
10+
next_window = 이전 window - μ•ž + λ’€
11+
=> sliding winodw을 톡해 window λ‚΄ λ§¨μ•žκ³Ό 맨 λ’€ κ°’λ§Œ κ΅¬ν•΄μ„œ λ”ν•˜κ³  λΉΌλ©΄ λ²”μœ„λ‚΄ 총합 ꡬ할 수 μžˆλ‹€.
12+
13+
"""
14+
import sys
15+
input = sys.stdin.readline
16+
#0. 전체 일수 = N , 연속 일수= K ,
17+
N , k = map(int,input().split())
18+
temp = list(map(int, input().split()))
19+
20+
# 1. 첫 window λ²”μœ„ μ΄ˆκΈ°ν™”
21+
sum_tmp = sum(temp[0:k]) # 초기 window λ‚΄ 리슀트의 ν•©
22+
max_sum = sum_tmp # μ΅œλŒ€κ°’μ„ window ν•© μ΄ˆκΈ°κ°’μœΌλ‘œ μ„€μ •
23+
# 2. 투 포인터 (s,e)을 μ΄λ™ν•˜μ—¬ window λ²”μœ„ ν•© κ΅¬ν•˜κΈ°
24+
# e :μƒˆλ‘œμš΄ window λ²”μœ„μ— λ“€μ–΄κ°€λŠ” κ°’
25+
# s :μƒˆλ‘œμš΄ window λ²”μœ„μ—μ„œ λΉ μ§€λŠ” κ°’
26+
for e in range(k, N):
27+
s = e-k # 0 n-k
28+
sum_tmp = sum_tmp - temp[s] + temp[e] # μƒˆλ‘œμš΄ window λ²”μœ„ λ‚΄μ˜ ν•©
29+
max_sum = max(max_sum , sum_tmp) #
30+
31+
print(max_sum)

β€ŽHongjoo/λ°±μ€€/μ•ˆμ „μ˜μ—­.pyβ€Ž

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
#ν”Όλ³΄λ‚˜μΉ˜ λΉ„μŠ€λ¬΄λ¦¬ν•œμˆ˜μ—΄ / 싀버 5
3+
https://www.acmicpc.net/problem/14495
4+
- 쑰건 : 1< n <=116
5+
6+
# 문제 μœ ν˜• : DP
7+
1. μž…λ ₯
8+
2. dp 생성
9+
dp[1<idx <=n] = [1,1,1...f(n)]
10+
-μ΄ˆκΈ°ν™” : dp[1]=dp[2]=dp[3] = 1
11+
12+
3. 점화식
13+
f(n) = f(n-1) + f(n-3)
14+
- dp에 μ €μž₯ν•˜κΈ°
15+
- dp에 있으면 호좜, μ—†μœΌλ©΄ 계산 & dp에 μ—…λ°μ΄νŠΈ
16+
"""
17+
#1. μž…λ ₯ λ³€μˆ˜ μ €μž₯
18+
N = int(input())
19+
#2. dp 생성 & μ΄ˆκΈ°ν™”
20+
dp = [ 0 for _ in range(116+1)]
21+
22+
23+
#3. 점화식
24+
for i in range(0,N+1) :
25+
if i in [0,1,2,3] :
26+
dp[i] = 1
27+
elif dp[i] == 0 : # i>=4, dp에 μ—†μœΌλ©΄ -> μ—…λ°μ΄νŠΈ
28+
29+
dp[i] = dp[i-1] + dp[i-3]
30+
31+
print(dp[N])
Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,59 @@
11
from collections import deque
22

3-
# 2차원 배열을 μ΄μš©ν•œ bfs κ΅¬ν˜„
4-
def bfs(x, y):
3+
dx = [-1, 1, 0, 0]
4+
dy = [0, 0, -1, 1]
55

6-
# 2차원 λ°°μ—΄μ—μ„œ ν˜„μž¬ λ…Έλ“œμ˜ μƒν•˜μ’Œμš°λ₯Ό κ²€μ‚¬ν•˜κΈ° μœ„ν•œ dx와 dy
7-
dx = [0, -1, 0, 1]
8-
dy = [-1, 0, 1, 0]
96

10-
# queueλ₯Ό μ΄μš©ν•œ bfs κ·Έλž˜ν”„ 탐색
11-
queue.append((x, y))
12-
visited[x][y] = 1
7+
def bfs(graph, visited):
8+
border = 0
9+
queue = deque()
1310

11+
# μ˜μ—­ 개수 계산
12+
for i in range(1, N + 1):
13+
for j in range(1, N + 1):
14+
# ν˜„μž¬ 칸을 아직 λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ ν˜„μž¬ μΉΈλΆ€ν„° bfs 탐색 μ‹œμž‘
15+
if visited[i][j] == 0:
16+
# μ˜μ—­ 개수 ν•œ 개 증가
17+
border += 1
18+
queue.append((i, j))
1419

15-
while queue:
16-
(x, y) = queue.popleft()
20+
while queue:
21+
(x, y) = queue.popleft()
22+
# 방문처리
23+
visited[x][y] = 1
1724

18-
# queueμ—μ„œ popν•œ ν˜„μž¬ λ…Έλ“œλ₯Ό κΈ°μ€€μœΌλ‘œ μƒν•˜μ’Œμš° 탐색
19-
for k in range(4):
20-
row = x + dx[k]
21-
col = y + dy[k]
25+
# μƒν•˜μ’Œμš° μΈμ ‘ν•œ 칸으둜 이동
26+
for k in range(4):
27+
nx = x + dx[k]
28+
ny = y + dy[k]
2229

23-
# 탐색 쑰건
24-
# 1. ν˜„μž¬ λ…Έλ“œκ°€ λ°°μ—΄μ˜ 인덱슀 λ²”μœ„ μ•ˆμΈμ§€ 0 <= x < n and 0 <= y < n
25-
# 2. 같은 색인지
26-
# 3. λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λŠ”μ§€
27-
if 0 <= row < n and 0 <= col < n:
28-
if arr[x][y] == arr[row][col] and visited[row][col] == 0:
29-
queue.append((row, col))
30-
visited[row][col] = 1
30+
# 칸이 λ³΄λ“œ λ°–μœΌλ‘œ λ„˜μ–΄κ°€μ§€ μ•Šμ•˜λŠ”μ§€,μΈμ ‘ν•œ 칸이 같은 색인지,아직 λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인
31+
if (1 <= nx <= N and 1 <= ny <= N) and graph[x][y] == graph[nx][ny] and visited[nx][ny] == 0:
32+
# ν•΄λ‹Ή μΉΈ 방문처리
33+
queue.append((nx, ny))
34+
visited[nx][ny] = 1
3135

36+
return border
3237

33-
# μ΄ˆκΈ°κ°’ μ„ΈνŒ…
34-
n = int(input())
35-
visited = [[0] * n for _ in range(n)]
36-
arr = [list(input()) for _ in range(n)]
37-
queue = deque()
3838

39-
# 적둝색약이 μ•„λ‹Œ 경우의 λ‹΅
40-
answerForNormal = 0
39+
# μž…λ ₯λ°›κΈ°
40+
N = int(input())
41+
graph = [[0] * (N + 1)]
42+
visited = [[0] * (N + 1) for _ in range(N + 1)]
4143

42-
# 적둝색약인 경우의 λ‹΅
43-
answerForColorBlindness = 0
44+
for _ in range(N):
45+
graph.append([0] + list(input()))
4446

47+
# 정상인이 λ³΄λŠ” μ˜μ—­ 개수 λ°˜ν™˜
48+
num_of_normal = bfs(graph, visited)
4549

46-
# 적둝색약이 μ•„λ‹Œ 경우
47-
for i in range(n):
48-
for j in range(n):
49-
if visited[i][j] == 0:
50-
bfs(i, j)
51-
answerForNormal += 1
50+
# 적둝색약이 λ³΄λŠ” μ˜μ—­ 개수 λ°˜ν™˜ 적둝색약은 R,Gλ₯Ό κ΅¬λΆ„ν•˜μ§€ λͺ»ν•˜λ―€λ‘œ λͺ¨λ“  R을 G둜 λ³€ν™˜
51+
for i in range(1, N + 1):
52+
for j in range(1, N + 1):
53+
if graph[i][j] == 'R':
54+
graph[i][j] = 'G'
5255

56+
visited = [[0] * (N + 1) for _ in range(N + 1)]
57+
num_of_abnormal = bfs(graph, visited)
5358

54-
# 적둝색약인 경우 Rκ³Ό GλŠ” κ°™μœΌλ―€λ‘œ
55-
56-
for i in range(n):
57-
for j in range(n):
58-
if arr[i][j] == 'G':
59-
arr[i][j] = 'R'
60-
61-
visited = [[0] * n for _ in range(n)]
62-
for i in range(n):
63-
for j in range(n):
64-
if not visited[i][j]:
65-
bfs(i,j)
66-
answerForColorBlindness += 1
67-
68-
print(answerForNormal, answerForColorBlindness)
59+
print(f"{num_of_normal} {num_of_abnormal}")
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'''
2+
3+
4+
농뢀 ν•΄κ°•μ΄λŠ” N X N칸으둜 이루어진 λ‚˜λ¬΄νŒμ—μ„œ 버섯 농사λ₯Ό μ§“λŠ”λ‹€. λ‚˜λ¬΄νŒμ€ 버섯이 μžλž„ 수 μžˆλŠ” μΉΈκ³Ό μ—†λŠ” 칸으둜 이루어져 μžˆλ‹€.
5+
6+
7+
각 버섯 ν¬μžλŠ” ν¬μžκ°€ 심어진 칸을 포함해 μ΅œλŒ€ K개의 μ—°κ²°λœ (버섯이 μžλž„ 수 μžˆλŠ”) 칸에 버섯을 자라게 ν•œλ‹€.
8+
μ΄λ•Œ μ—°κ²°λœ 칸은 μƒν•˜μ’Œμš°λ‘œ 적어도 ν•œ 변을 κ³΅μœ ν•˜λŠ” μΉΈλ“€μ˜ 집합이라고 μ •μ˜ν•œλ‹€.
9+
10+
λ˜ν•œ ν•œ 칸에 버섯 포자λ₯Ό μ—¬λŸ¬ 개 κ²Ήμ³μ„œ 심을 수 있으며, λ§Œμ•½ x개의 버섯 포자λ₯Ό 겹쳐 μ‹¬μœΌλ©΄ ν¬μžκ°€ 심어진 칸을 포함해 μ΅œλŒ€
11+
x X K개의 μ—°κ²°λœ (버섯이 μžλž„ 수 μžˆλŠ”) 칸에 버섯이 μžλž€λ‹€.
12+
13+
14+
ν•΄κ°•μ΄λŠ” 버섯 포자λ₯Ό 심을 λ•Œ μ΅œμ†Œ 개수둜만 μ‹¬μœΌλ €κ³  ν•œλ‹€.
15+
해강이가 농사가 κ°€λŠ₯ν• μ§€ νŒλ‹¨ν•˜κ³ , 농사가 κ°€λŠ₯ν•˜λ‹€λ©΄ 남은 버섯 포자의 개수λ₯Ό 좜λ ₯ν•˜μ‹œμ˜€.
16+
버섯 포자λ₯Ό ν•˜λ‚˜λΌλ„ μ‚¬μš©ν•˜κ³  버섯이 μžλž„ 수 μžˆλŠ” λͺ¨λ“  칸에 버섯이 μ „λΆ€ μžλžμ„ λ•Œ 농사가 κ°€λŠ₯ν•˜λ‹€κ³  μ •μ˜ν•œλ‹€.
17+
18+
1. N X N μΉΈμ—μ„œ 버섯을 심어야 함. μ΄λ•Œ 심은 버섯은 μƒν•˜μ’Œμš° μ΅œλŒ€ K칸으둜 ν™•μ‚°.
19+
(버섯을 심은 칸을 μ‹œμž‘μœΌλ‘œ BFS 탐색 μ§„ν–‰ν•˜λ©΄ ν•΄λ‹Ή μΉΈμœΌλ‘œλΆ€ν„° 버섯을 심을 수 μžˆλŠ” μΈμ ‘ν•œ 칸이 λͺ‡κ°œμΈμ§€ μ•Œμˆ˜ 있음)
20+
21+
2. 2차원 배열을 μˆœνšŒν•˜λ©° 칸이 0이고 아직 λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ κ±°κΈ°μ„œλΆ€ν„° BFS 탐색 μ‹œμž‘.
22+
3. BFS νƒμƒ‰μœΌλ‘œ ν•΄λ‹Ή μΉΈμœΌλ‘œλΆ€ν„° μƒν•˜μ’Œμš° μΈμ ‘ν•œ 0(버섯 농사 κ°€λŠ₯ μΉΈ)이 λͺ‡ κ°œμΈμ§€ νŒŒμ•…ν›„ K개둜 λ‚˜λˆ„λ©΄ ν•΄λ‹Ή ꡬ역에 λͺ‡κ°œμ˜ 버섯 ν¬μžκ°€ ν•„μš”ν•œμ§€ 계산 κ°€λŠ₯
23+
4. 2-3을 λ°˜λ³΅ν•˜λ©° λͺ¨λ“  버섯 농사 κ°€λŠ₯ ꡬ역을 μ„Έλ©° 총 λͺ‡κ°œμ˜ 버섯 ν¬μžκ°€ ν•„μš”ν•œμ§€ 계산
24+
5. ν•„μš”ν•œ 버섯 포자 κ°œμˆ˜κ°€ M보닀 크면 남은 버섯 개수λ₯Ό 좜λ ₯ κ·Έλ ‡μ§€ μ•Šλ‹€λ©΄ IMPOSSIBLE 좜λ ₯.
25+
5-1. 이떄 버섯 포자λ₯Ό ν•˜λ‚˜λ„ μ‚¬μš©ν•˜μ§€ μ•Šμ•„λ„ IMPOSSIBLE 좜λ ₯
26+
27+
'''
28+
29+
from collections import deque
30+
31+
32+
def bfs(i, j, visited):
33+
dx = [-1, 1, 0, 0]
34+
dy = [0, 0, -1, 1]
35+
36+
queue = deque()
37+
38+
# μ‹œμž‘μ  방문처리
39+
queue.append((i, j))
40+
visited[i][j] = 1
41+
42+
# μ‹œμž‘μ (x,y)μœΌλ‘œλΆ€ν„° μΈμ ‘ν•œ 버섯 농사 κ°€λŠ₯ 칸의 개수 (μ‹œμž‘μ  포함)
43+
num = 1
44+
45+
while queue:
46+
x, y = queue.popleft()
47+
48+
# μƒν•˜μ’Œμš° μΈμ ‘ν•œ 칸에 버섯 농사 κ°€λŠ₯ν•œμ§€ 보기
49+
for k in range(4):
50+
nx = x + dx[k]
51+
ny = y + dy[k]
52+
53+
# κ·Έλž˜ν”„ λ²”μœ„μ— μžˆλŠ”μ§€, 버섯 농사가 κ°€λŠ₯ν•œμ§€, 아직 λ°©λ¬Έν•˜μ§€ μ•Šμ•˜λŠ”μ§€ 확인
54+
if (0 <= nx <= N - 1 and 0 <= ny <= N - 1) and graph[nx][ny] == 0 and visited[nx][ny] == 0:
55+
# 방문처리
56+
queue.append((nx, ny))
57+
visited[nx][ny] = 1
58+
# 버섯 농사 κ°€λŠ₯ν•œ 칸의 개수 증가
59+
num += 1
60+
61+
# ν•΄λ‹Ή ꡬ역에 ν•„μš”ν•œ 버섯 포자 개수 λ°˜ν™˜
62+
if num % K == 0:
63+
return num // K
64+
else:
65+
return (num // K) + 1
66+
67+
68+
# μž…λ ₯λ°›κΈ°
69+
N, M, K = map(int, input().split())
70+
71+
# λ‚˜λ¬΄νŒ λ°°μ—΄
72+
graph = []
73+
# λ‚˜λ¬΄νŒ λ°©λ¬Έ λ°°μ—΄
74+
visited = [[0] * N for _ in range(N)]
75+
76+
mushroom_count = 0
77+
78+
for _ in range(N):
79+
graph.append(list(map(int, input().split())))
80+
81+
for i in range(N):
82+
for j in range(N):
83+
# λ‚˜λ¬΄νŒμ΄ 버섯을 심을 수 있고, 아직 λ°©λ¬Έν•˜μ§€ μ•Šμ•˜μœΌλ©΄
84+
if graph[i][j] == 0 and visited[i][j] == 0:
85+
mushroom_count += bfs(i, j, visited)
86+
87+
if mushroom_count == 0 or mushroom_count > M:
88+
print("IMPOSSIBLE")
89+
else:
90+
print(f"POSSIBLE\n{M - mushroom_count}")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
# 두 단어가 ν•œκΈ€μžλ§Œ λ‹€λ₯Έμ§€ ν™•μΈν•˜λŠ” ν•¨μˆ˜
3+
def count_same_letter(word1, word2):
4+
5+
count = 0
6+
word_length = len(word1)
7+
# λͺ¨λ“  λ‹¨μ–΄μ˜ κΈΈμ΄λŠ” κ°™μœΌλ―€λ‘œ λ‹¨μ–΄μ˜ 길이만큼 반볡문 λŒλ©΄μ„œ 같은 κΈ€μž 계산
8+
for i in range(word_length):
9+
if word1[i] == word2[i]:
10+
count += 1
11+
12+
if word_length - 1 == count:
13+
return True
14+
else:
15+
return False
16+
17+
18+
19+
def dfs(begin, target, words, depth):
20+
global words_num
21+
global min_value
22+
23+
# depthκ°€ words의 크기보닀 컀지면 ν•΄λ‹Ή 탐색 μ’…λ£Œ
24+
if depth > words_num:
25+
return
26+
27+
# beginκ³Ό target이 κ°™λ‹€λ©΄ 탐색 μ’…λ£Œ
28+
if begin == target:
29+
# ν˜„μž¬ depth와 μ΅œμ†Ÿκ°’ 비ꡐ
30+
min_value = min(min_value, depth)
31+
return
32+
33+
copy_words = words[:]
34+
35+
for i in range(len(words)):
36+
# 두 단어가 ν•œκΈ€μžλ§Œ λ‹€λ₯΄λ‹€λ©΄ κ·Έ λ‹¨μ–΄λ‘œ λ³€ν™˜
37+
if count_same_letter(begin, words[i]):
38+
# 단어 λͺ©λ‘μ—μ„œ ν˜„μž¬ 단어 μ œμ™Έν•˜κ³ 
39+
removed_word = copy_words.pop(i)
40+
# λ‹€μŒ detph dfs μ‹€ν–‰
41+
dfs(removed_word, target, copy_words, depth + 1)
42+
# λ°°μ—΄ 원볡
43+
copy_words.insert(i, removed_word)
44+
45+
46+
47+
48+
def solution(begin, target, words):
49+
50+
# target이 words에 μ—†μ–΄μ„œ λ³€ν™˜ν•  수 μ—†λŠ” 경우
51+
if target not in words:
52+
return 0
53+
54+
# λ‹¨μ–΄μ˜ 개수
55+
global words_num
56+
words_num = len(words)
57+
58+
global min_value
59+
min_value = 10000
60+
61+
dfs(begin, target, words, 0)
62+
63+
return min_value

β€Ž_MonthlyChallenges/DASHBOARD.mdβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
| μ‚¬μš©μž | μ±Œλ¦°μ§€ μœ ν˜• | 문제 수 | 달성 μ—¬λΆ€ |
44
| ------ | ----------- | ------- | --------- |
5-
| Mingguriguri | κ·Έλž˜ν”„ | 2 | ❌ |
6-
| Mingguriguri | DP | 6 | βœ… |
5+
| Mingguriguri | κ·Έλž˜ν”„ | 0 | ❌ |
6+
| Mingguriguri | DP | 5 | βœ… |
7+
| zaqquum | κ·Έλž˜ν”„ | 0 | ❌ |
8+
| zaqquum | DP | 2 | ❌ |

β€Ž_MonthlyChallenges/scoreboard.jsonβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
"κ·Έλž˜ν”„": false,
1919
"DP": true
2020
}
21+
},
22+
"zaqquum": {
23+
"κ·Έλž˜ν”„": [],
24+
"DP": [
25+
2169,
26+
1520
27+
],
28+
"achieved": {
29+
"κ·Έλž˜ν”„": false,
30+
"DP": false
31+
}
2132
}
2233
}
2334
}

0 commit comments

Comments
Β (0)