diff --git "a/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_K\353\262\210\354\247\270 \354\210\230.py" "b/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_K\353\262\210\354\247\270 \354\210\230.py" similarity index 100% rename from "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_K\353\262\210\354\247\270 \354\210\230.py" rename to "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_K\353\262\210\354\247\270 \354\210\230.py" diff --git "a/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\353\252\250\354\235\230\352\263\240\354\202\254.py" "b/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\353\252\250\354\235\230\352\263\240\354\202\254.py" similarity index 100% rename from "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\353\252\250\354\235\230\352\263\240\354\202\254.py" rename to "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\353\252\250\354\235\230\352\263\240\354\202\254.py" diff --git "a/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\213\244\355\214\250\354\234\250.py" "b/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\213\244\355\214\250\354\234\250.py" similarity index 100% rename from "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\213\244\355\214\250\354\234\250.py" rename to "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\213\244\355\214\250\354\234\250.py" diff --git "a/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.py" "b/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.py" similarity index 100% rename from "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.py" rename to "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\240\204\355\231\224\353\262\210\355\230\270\353\252\251\353\241\235.py" diff --git "a/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\272\220\353\246\255\355\204\260\354\235\230 \354\242\214\355\221\234.py" "b/\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\272\220\353\246\255\355\204\260\354\235\230 \354\242\214\355\221\234.py" similarity index 100% rename from "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250_\354\272\220\353\246\255\355\204\260\354\235\230 \354\242\214\355\221\234.py" rename to "\355\231\251\353\213\244\352\262\275/1\354\243\274\354\260\250/1\354\243\274\354\260\250_\354\272\220\353\246\255\355\204\260\354\235\230 \354\242\214\355\221\234.py" diff --git "a/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.py" "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.py" new file mode 100644 index 0000000..0278719 --- /dev/null +++ "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\352\262\275\354\243\274\353\241\234 \352\261\264\354\204\244.py" @@ -0,0 +1,33 @@ +from collections import deque + +def solution(board): + n = len(board) + INF = int(1e9) + + directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] + + cost = [[[INF] * 4 for _ in range(n)] for _ in range(n)] + q = deque() + + for i, (dx, dy) in enumerate(directions): + nx, ny = dx, dy + if 0 <= nx < n and 0 <= ny < n and board[nx][ny] == 0: + cost[nx][ny][i] = 100 + q.append((nx, ny, i, 100)) + + while q: + x, y, dir_prev, c = q.popleft() + + for i, (dx, dy) in enumerate(directions): + nx, ny = x + dx, y + dy + if 0 <= nx < n and 0 <= ny < n and board[nx][ny] == 0: + if i == dir_prev: + nc = c + 100 + else: + nc = c + 600 + + if nc < cost[nx][ny][i]: + cost[nx][ny][i] = nc + q.append((nx, ny, i, nc)) + + return min(cost[n-1][n-1]) \ No newline at end of file diff --git "a/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\204\244\355\212\270\354\233\214\355\201\254.py" "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\204\244\355\212\270\354\233\214\355\201\254.py" new file mode 100644 index 0000000..4dcb404 --- /dev/null +++ "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\204\244\355\212\270\354\233\214\355\201\254.py" @@ -0,0 +1,16 @@ +def solution(n, computers): + visited = [False] * n + + def dfs(node): + visited[node] = True + for next_node in range(n): + if not visited[next_node] and computers[node][next_node] == 1: + dfs(next_node) + + count = 0 + for i in range(n): + if not visited[i]: + dfs(i) + count += 1 + + return count \ No newline at end of file diff --git "a/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" new file mode 100644 index 0000000..a1aa880 --- /dev/null +++ "b/\355\231\251\353\213\244\352\262\275/3\354\243\274\354\260\250/3\354\243\274\354\260\250_\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.py" @@ -0,0 +1,28 @@ +def solution(maps): + n, m = len(maps), len(maps[0]) + + visited = [[False] * m for _ in range(n)] + + directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] + results = [] + + for i in range(n): + for j in range(m): + if not visited[i][j] and maps[i][j] != 'X': + stack = [(i, j)] + visited[i][j] = True + total = 0 + + while stack: + x, y = stack.pop() + total += int(maps[x][y]) + + for dx, dy in directions: + nx, ny = x + dx, y + dy + if 0 <= nx < n and 0 <= ny