Skip to content

Commit

Permalink
Merge branch 'main' into 58-tgyuuAn
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored May 31, 2024
2 parents 90009df + 408b7ce commit 8cbce65
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 1 deletion.
46 changes: 46 additions & 0 deletions H0ngJu/BFS/์ ๋ก์ƒ‰์•ฝ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
sys.setrecursionlimit(10**6)
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N = int(input())
arr = [[i for i in input()]for _ in range(N)]
visited = [[0] * N for _ in range(N)]
direc = [(1,0), (-1,0), (0,1), (0,-1)]
result = [0, 0]

def bfs(x, y, color):
q = deque([(x,y)])
visited[x][y] = 1
while q:
cx, cy = q.popleft()
for dx, dy in direc:
nx = dx + cx
ny = dy + cy
if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color:
q.append((nx, ny))
visited[nx][ny] = 1


for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[0] += 1

visited = [[0] * N for _ in range(N)]

for i in range(N):
for j in range(N):
if arr[i][j] == "R":
arr[i][j] = "G"

for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[1] += 1


print(result[0], result[1], end=" ")
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
sys.setrecursionlimit(10**6)

def input(): return sys.stdin.readline().rstrip()

N = int(input())
eggs = [list(map(int, input().split())) for _ in range(N)]

def break_egg(idx):
cnt = 0

# idx๊ฐ€ ๋„˜์–ด๊ฐ„ ๊ฒฝ์šฐ
if idx == N:
for i in range(N):
if eggs[i][0] <= 0:
cnt += 1
return cnt

if eggs[idx][0] <= 0: # ๋“ค๊ณ  ์žˆ๋Š” ๊ณ„๋ž€์ด ๊นจ์ง„ ๊ฒฝ์šฐ
return break_egg(idx+1)

broken = False
for j in range(N): # ๊ณ„๋ž€ ๊นจ๊ธฐ
if j != idx and eggs[j][0] > 0:
broken = True
eggs[idx][0] -= eggs[j][1]
eggs[j][0] -= eggs[idx][1]

cnt = max(cnt, break_egg(idx+1))

eggs[idx][0] += eggs[j][1]
eggs[j][0] += eggs[idx][1]

if not broken:
return break_egg(idx+1)

return cnt

print(break_egg(0))
2 changes: 2 additions & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
| 14์ฐจ์‹œ | 2024.05.09 | DFS | [์น˜ํ‚จ๋ฐฐ๋‹ฌ](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 |
| 15์ฐจ์‹œ | 2024.05.14 | ๊ทธ๋ฆฌ๋”” | [A์™€ B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 16์ฐจ์‹œ | 2024.05.14 | BFS | [๋ฑ€๊ณผ ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 |
| 17์ฐจ์‹œ | 2024.05.22 | BFS | [์ ๋ก์ƒ‰์•ฝ](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 |
| 17์ฐจ์‹œ | 2024.05.26 | DFS | [๊ณ„๋ž€์œผ๋กœ ๊ณ„๋ž€์น˜๊ธฐ](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 |

---
2 changes: 2 additions & 0 deletions SeongHoonC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
| 22์ฐจ์‹œ | 2024.05.01 | DP | <a href="https://www.acmicpc.net/problem/11053">๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/80 |
| 23์ฐจ์‹œ | 2024.05.14 | ์†Œ์ˆ˜ | <a href="https://www.acmicpc.net/problem/1644">์†Œ์ˆ˜์˜ ์—ฐ์†ํ•ฉ</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/186 |
| 24์ฐจ์‹œ | 2024.05.18| ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/9663">n-queen</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/192 |
| 25์ฐจ์‹œ | 2024.05.22| ๋ธŒ๋ฃจํŠธํฌ์Šค | <a href="https://www.acmicpc.net/problem/14500">ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/194 |
| 26์ฐจ์‹œ | 2024.05.26| ๊ทธ๋ž˜ํ”„ | <a href="https://www.acmicpc.net/problem/1389">์ผ€๋นˆ ๋ฒ ์ด์ปจ์˜ 6๋‹จ๊ณ„ ๋ฒ•์น™</a> |https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/200 |
---
40 changes: 40 additions & 0 deletions SeongHoonC/graph/์บ๋นˆ๋ฒ ์ด์ปจ.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.BufferedReader
import java.io.InputStreamReader

private const val INF = 987_654_321
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val (n, m) = br.readLine().split(" ").map { it.toInt() }
val graph = Array(n + 1) { i ->
Array(n + 1) { j -> if (i == j) 0 else INF }
}

repeat(m) {
val (a, b) = br.readLine().split(" ").map { it.toInt() }
graph[a][b] = 1
graph[b][a] = 1
}

for (k in 1..n) {
for (i in 1..n) {
for (j in 1..n) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j]
}
}
}
}

var min = INF
var answer = -1

for (i in 1..n) {
val sum = (1..n).sumOf { j -> graph[i][j] }
if (min > sum) {
min = sum
answer = i
}
}

println(answer)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max

val t1 = listOf(0 to 0, 0 to 1, 0 to 2, 0 to 3)
val t2 = listOf(0 to 0, 0 to 1, 1 to 0, 1 to 1)
val t3 = listOf(0 to 0, 1 to 0, 2 to 0, 2 to 1)
val t4 = listOf(0 to 0, 1 to 0, 1 to 1, 2 to 1)
val t5 = listOf(0 to 0, 0 to 1, 0 to 2, 1 to 1)
val tetrominos = listOf(t1, t2, t3, t4, t5)

private var n: Int = 0
private var m: Int = 0
private lateinit var board: Array<Array<Int>>
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val input = br.readLine().split(" ").map { it.toInt() }
n = input[0]
m = input[1]

board = Array(n) { Array(m) { 0 } }
// ์ˆซ์ž๋ฅผ ๋ณด๋“œ์— ์„ธํŒ…
repeat(n) {
val line = br.readLine().split(" ").map { it.toInt() }
line.forEachIndexed { index, value -> board[it][index] = value }
}

var maxTetromino = 0

// 0,0 ๋ถ€ํ„ฐ n-1, m-1 ๊นŒ์ง€ ํƒ์ƒ‰
for (x in 0 until n) {
for (y in 0 until m) {
tetrominos.forEach { tetromino ->
// ๊ทธ๋Œ€๋กœ
maxTetromino = max(maxTetromino, sumAllDirection(x, y, tetromino))
// ๋’ค์ง‘์–ด์„œ
maxTetromino = max(maxTetromino, sumAllDirection(x, y, tetromino.reverseTetromino()))
}
}
}
println(maxTetromino)
}

// 90๋„์”ฉ ํšŒ์ „์‹œ์ผœ ์ตœ๋Œ€๊ฐ’ return
private fun sumAllDirection(x: Int, y: Int, tetromino: List<Pair<Int, Int>>): Int {
var maxTetromino = 0
var nowTetromino = tetromino
repeat(4) {
maxTetromino = max(maxTetromino, sumTetromino(x, y, nowTetromino))
nowTetromino = nowTetromino.translate()
}
return maxTetromino
}

// board ์˜ tetromino ์ˆซ์ž ํ•ฉ ๊ณ„์‚ฐ
private fun sumTetromino(x: Int, y: Int, tetromino: List<Pair<Int, Int>>): Int {
var sum = 0
for (move in tetromino) {
val nowX = x + move.first
val nowY = y + move.second
if (nowX >= n || nowY >= m || nowX < 0 || nowY < 0) {
return -1
}
sum += board[nowX][nowY]
}
return sum
}

// tetromino ๋ฅผ 90๋„ ํšŒ์ „
private fun List<Pair<Int, Int>>.translate() = map { it.second to -1 * it.first }

// tetromino ๋ฅผ ๋’ค์ง‘๊ธฐ
private fun List<Pair<Int, Int>>.reverseTetromino() = map { it.first to (it.second * -1) }
4 changes: 3 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
| 22์ฐจ์‹œ | 2024.04.13 | BFS | <a href="https://www.acmicpc.net/problem/11724">์—ฐ๊ฒฐ ์š”์†Œ์˜ ๊ฐœ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/78 |
| 23์ฐจ์‹œ | 2024.05.01 | ํ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42587">ํ”„๋กœ์„ธ์Šค</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/79 |
| 24์ฐจ์‹œ | 2024.05.14 | BFS | <a href="https://www.acmicpc.net/problem/7576">ํ† ๋งˆํ† </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/187 |
| 25์ฐจ์‹œ | 2024.05.18 | ๋ฑ | <a href="https://www.acmicpc.net/problem/5430">AC</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/190 |
| 25์ฐจ์‹œ | 2024.05.18 | ๋ฑ | <a href="https://www.acmicpc.net/problem/5430">AC</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/190 |
| 26์ฐจ์‹œ | 2024.05.22 | ์ •๋ ฌ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/42747">H-Index</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/196 |
| 27์ฐจ์‹œ | 2024.05.26 | ์šฐ์„ ์ˆœ์œ„ ํ | <a href="https://www.acmicpc.net/problem/7662">์ด์ค‘ ์šฐ์„ ์ˆœ์œ„ ํ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/198 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from heapq import *
import sys

input = sys.stdin.readline

t = int(input())

for _ in range(t):
q = int(input())

# ์ตœ์†Œํž™๋งŒ ์ง€์›ํ•ด์„œ ์ตœ๋Œ€, ์ตœ์†Œ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ
min_heap = []
max_heap = []
nums = [False] * q # ๋™๊ธฐํ™”๋ฅผ ์œ„ํ•œ ๋ถ€๋ถ„

for i in range(q):
k = list(input().split())
iNum = int(k[1])

# ์ž…๋ ฅ ๋ถ€๋ถ„
if k[0] == "I" :
heappush(min_heap, (iNum,i)) # ๋™๊ธฐํ™”๋ฅผ ์œ„ํ•œ i๋„ ํŠœํ”Œ๋กœ ๋„ฃ์–ด์ฃผ๊ธฐ
heappush(max_heap, (-iNum, i))
nums[i] = True
elif iNum == 1:
while max_heap and not nums[max_heap[0][1]]:
heappop(max_heap)
if max_heap: # max_heap์—์„œ ์ž‘์€ ์ˆ˜ ์ œ๊ฑฐ
nums[max_heap[0][1]] = False
heappop(max_heap)
else:
while min_heap and not nums[min_heap[0][1]]: # ์ด๋ฏธ ์‚ญ์ œ๋œ ๋…ธ๋“œ์ธ ๊ฒฝ์šฐ ์‚ญ์ œ๋˜์ง€ ์•Š์€ ๋…ธ๋“œ ๋‚˜์˜ฌ๋•Œ๊นŒ์ง€ ๋ชจ๋‘ ๋ฒ„๋ฆผ
heappop(min_heap)
if min_heap: # min_heap์—์„œ ์ž‘์€ ์ˆ˜(์‚ญ์ œ ๋…ธ๋“œ) ์ œ๊ฑฐ
nums[min_heap[0][1]] = False
heappop(min_heap)
# print(min_heap, max_heap, nums, k)
# ๋ชจ๋“  ์—ฐ์‚ฐ ํ›„ ๋™๊ธฐํ™” ๋˜์ง€ ์•Š์€ ๋…ธ๋“œ ์ฒ˜๋ฆฌ
while min_heap and not nums[min_heap[0][1]]:
heappop(min_heap)
while max_heap and not nums[max_heap[0][1]]:
heappop(max_heap)

if max_heap and min_heap :
print(-max_heap[0][0], min_heap[0][0])
else :
print("EMPTY")
8 changes: 8 additions & 0 deletions alstjr7437/์ •๋ ฌ/H-Index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def solution(citations):
citations.sort(reverse=True)

for i in range(len(citations)):
if(citations[i] < i+1):
return i

return len(citations)
2 changes: 2 additions & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
| 53์ฐจ์‹œ | 2024.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 54์ฐจ์‹œ | 2024.05.14 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/9370">๋ฏธํ™•์ธ ๋„์ฐฉ์ง€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185
| 55์ฐจ์‹œ | 2023.05.18 | ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ | <a href="https://www.acmicpc.net/problem/4195">์นœ๊ตฌ ๋„คํŠธ์›Œํฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189
| 56์ฐจ์‹œ | 2023.05.18 | BFS | <a href="https://www.acmicpc.net/problem/17836">๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•ด๋ผ!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/193
| 57์ฐจ์‹œ | 2023.05.26 | ๋ถ„ํ•  ์ •๋ณต | <a href="https://www.acmicpc.net/problem/2263">ํŠธ๋ฆฌ์˜ ์ˆœํšŒ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/197
| 58์ฐจ์‹œ | 2023.05.30 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/1799">๋น„์ˆ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/204
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()

N = int(input())
in_order = list(map(int,input().split()))
post_order = list(map(int,input().split()))
position = [0 for _ in range(N+1)]

for idx, element in enumerate(in_order):
position[element] = idx

def divide_and_conquer(in_start, in_end, post_start, post_end):
if in_start > in_end or post_start > post_end: return

in_order_root = post_order[post_end]
print(in_order_root, end=" ")

root_idx = position[in_order_root]

divide_and_conquer(in_start, root_idx-1, post_start, post_start+(root_idx - in_start) -1)
divide_and_conquer(root_idx+1, in_end, post_start+(root_idx - in_start), post_end-1)

return

divide_and_conquer(0, N-1, 0, N-1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from heapq import *
import sys

def input(): return sys.stdin.readline().rstrip()

N, M, T = map(int, input().split())
board = []

for _ in range(N):
board.append(input().split())

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
heap = [(0, 0, 0)]
answer = int(1e9)
visited = {(0,0),}
while heap:
now_time, now_row, now_col = heappop(heap)

if now_row == N-1 and now_col == M-1:
answer = min(answer, now_time)
break

if now_time >= T: continue

for dir in range(4):
new_row = now_row + dy[dir]
new_col = now_col + dx[dir]

if new_row < 0 or new_row >= N: continue
if new_col < 0 or new_col >= M: continue
if (new_row, new_col) in visited: continue

if board[new_row][new_col] == "2":
heappush(heap, (now_time+1, new_row, new_col))
answer = min(answer, (now_time+1+(N-1-new_row)+(M-1-new_col)))

elif board[new_row][new_col] == "0":
heappush(heap, (now_time+1, new_row, new_col))

visited.add((new_row, new_col))

print(answer) if answer <= T else print("Fail")

0 comments on commit 8cbce65

Please sign in to comment.