From a0fe1a19e9fec2dd9653f3216b2292fc8e1f1f11 Mon Sep 17 00:00:00 2001 From: JunHyeon Date: Tue, 4 Apr 2023 20:08:14 +0900 Subject: [PATCH 1/3] refact --- ...\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" | 0 ...3\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" | 0 .../14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" | 0 .../15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" | 0 .../\354\235\264\354\244\200\355\230\204/9663 N-Queen.py" | 0 ...3\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename "week-31/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" => "week-31/\354\235\264\354\244\200\355\230\204/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" (100%) rename "week-31/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" => "week-31/\354\235\264\354\244\200\355\230\204/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" (100%) rename "week-31/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" => "week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" (100%) rename "week-31/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" => "week-31/\354\235\264\354\244\200\355\230\204/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" (100%) rename week-31/9663 N-Queen.py => "week-31/\354\235\264\354\244\200\355\230\204/9663 N-Queen.py" (100%) rename "week-31/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" => "week-31/\354\235\264\354\244\200\355\230\204/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" (100%) diff --git "a/week-31/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" "b/week-31/\354\235\264\354\244\200\355\230\204/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" similarity index 100% rename from "week-31/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" rename to "week-31/\354\235\264\354\244\200\355\230\204/11660 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.py" diff --git "a/week-31/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" "b/week-31/\354\235\264\354\244\200\355\230\204/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" similarity index 100% rename from "week-31/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" rename to "week-31/\354\235\264\354\244\200\355\230\204/1182 \353\266\200\353\266\204\354\210\230\354\227\264\354\235\230 \355\225\251.py" diff --git "a/week-31/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" "b/week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" similarity index 100% rename from "week-31/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" rename to "week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" diff --git "a/week-31/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" "b/week-31/\354\235\264\354\244\200\355\230\204/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" similarity index 100% rename from "week-31/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" rename to "week-31/\354\235\264\354\244\200\355\230\204/15961 \355\232\214\354\240\204\354\264\210\353\260\245.py" diff --git a/week-31/9663 N-Queen.py "b/week-31/\354\235\264\354\244\200\355\230\204/9663 N-Queen.py" similarity index 100% rename from week-31/9663 N-Queen.py rename to "week-31/\354\235\264\354\244\200\355\230\204/9663 N-Queen.py" diff --git "a/week-31/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" "b/week-31/\354\235\264\354\244\200\355\230\204/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" similarity index 100% rename from "week-31/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" rename to "week-31/\354\235\264\354\244\200\355\230\204/\352\263\240\354\235\264\353\212\224 \353\271\227\353\254\274\354\235\230 \354\264\235\353\237\211.py" From a1599e4639a609c9bc3acecd668d9ec8301852fe Mon Sep 17 00:00:00 2001 From: JunHyeon Date: Thu, 6 Apr 2023 13:46:05 +0900 Subject: [PATCH 2/3] =?UTF-8?q?31=EC=A3=BC=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15652 N\352\263\274 M 2.py" | 27 +++++++++++++++++ ...\353\240\244\352\260\200\352\270\260 2.py" | 30 +++++++++++++++++++ ...64\353\252\250\353\204\264\353\252\250.py" | 3 +- ...4 \354\236\254\355\203\234\355\201\254.py" | 0 ...35\353\260\260\353\260\260\354\206\241.py" | 30 +++++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 "week-30/\354\235\264\354\244\200\355\230\204/15652 N\352\263\274 M 2.py" create mode 100644 "week-30/\354\235\264\354\244\200\355\230\204/2096 \353\202\264\353\240\244\352\260\200\352\270\260 2.py" create mode 100644 "week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" create mode 100644 "week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" diff --git "a/week-30/\354\235\264\354\244\200\355\230\204/15652 N\352\263\274 M 2.py" "b/week-30/\354\235\264\354\244\200\355\230\204/15652 N\352\263\274 M 2.py" new file mode 100644 index 0000000..5eacb12 --- /dev/null +++ "b/week-30/\354\235\264\354\244\200\355\230\204/15652 N\352\263\274 M 2.py" @@ -0,0 +1,27 @@ +import sys + +input = sys.stdin.readline +n, m = map(int, input().split()) + +li = list(range(1, n + 1)) + +check = [0] * m +ans = [] + + +def DFS(depth): + if depth == m: + ans.append(list(map(int, check))) + return + for k in range(n): + if check[depth - 1] <= li[k]: + check[depth] = li[k] + DFS(depth + 1) +for i in range(n): + check[0] = li[i] + DFS(1) + check[0] = 0 +for i in ans: + for j in i: + print(j, end=' ') + print() diff --git "a/week-30/\354\235\264\354\244\200\355\230\204/2096 \353\202\264\353\240\244\352\260\200\352\270\260 2.py" "b/week-30/\354\235\264\354\244\200\355\230\204/2096 \353\202\264\353\240\244\352\260\200\352\270\260 2.py" new file mode 100644 index 0000000..ec94594 --- /dev/null +++ "b/week-30/\354\235\264\354\244\200\355\230\204/2096 \353\202\264\353\240\244\352\260\200\352\270\260 2.py" @@ -0,0 +1,30 @@ +import sys + +input = sys.stdin.readline + +n = int(input()) + +max_dp = [0] * 3 +min_dp = [0] * 3 + +max_tmp = [0] * 3 +min_tmp = [0] * 3 + +for i in range(n): + a, b, c = map(int, input().split()) + for j in range(3): + if j == 0: + max_tmp[j] = a+ max(max_dp[j], max_dp[j + 1]) + min_tmp[j] = a + min(min_dp[j], min_dp[j + 1]) + elif j == 1: + max_tmp[j] = b + max(max_dp[j - 1], max_dp[j], max_dp[j + 1]) + min_tmp[j] = b + min(min_dp[j - 1], min_dp[j], min_dp[j + 1]) + else: + max_tmp[j] = c + max(max_dp[j], max_dp[j - 1]) + min_tmp[j] = c + min(min_dp[j], min_dp[j - 1]) + + for j in range(3): + max_dp[j] = max_tmp[j] + min_dp[j] = min_tmp[j] + +print(max(max_dp), min(min_dp)) \ No newline at end of file diff --git "a/week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" "b/week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" index f6c0006..f555f06 100644 --- "a/week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" +++ "b/week-31/\354\235\264\354\244\200\355\230\204/14712 \353\204\264\353\252\250\353\204\264\353\252\250.py" @@ -21,5 +21,6 @@ def DFS(x, y): DFS(nx, ny) graph[x][y] = False + DFS(1, 1) -print(ans) \ No newline at end of file +print(ans) diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" "b/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" new file mode 100644 index 0000000..e69de29 diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" "b/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" new file mode 100644 index 0000000..e65dc21 --- /dev/null +++ "b/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" @@ -0,0 +1,30 @@ +import sys +from collections import deque + +input = sys.stdin.readline +INF = 1e9 + +n, m = map(int, input().split()) +distance = [INF] * (n + 1) +graph = [[] for i in range(n + 1)] +for i in range(m): + a, b, d = map(int, input().split()) + graph[a].append((b, d)) + graph[b].append((a, d)) + +q = deque() +q.reverse(); +q.append((1, 0)) +q.ap +distance[1] = 0 +while q: + v, dist = q.popleft() + if distance[v] < dist: + continue + for i in graph[v]: + cost = dist + i[1] + if cost < distance[i[0]]: + distance[i[0]] = cost + q.append((i[0], cost)) + +print(distance[n]) From a8e6a18fd91cb2272c8e868f202e4f74d1e697fd Mon Sep 17 00:00:00 2001 From: JunHyeon Date: Tue, 11 Apr 2023 09:53:22 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\236\254\355\203\234\355\201\254.py" | 55 +++++++++++++ ...\354\230\256\352\270\260\352\270\260 1.py" | 78 +++++++++++++++++++ ...6 \353\260\261\353\217\204\354\226\264.py" | 36 +++++++++ ...35\353\260\260\353\260\260\354\206\241.py" | 3 +- 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 "week-32/\354\235\264\354\244\200\355\230\204/17070 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 1.py" create mode 100644 "week-32/\354\235\264\354\244\200\355\230\204/17396 \353\260\261\353\217\204\354\226\264.py" diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" "b/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" index e69de29..166836e 100644 --- "a/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" +++ "b/week-32/\354\235\264\354\244\200\355\230\204/16235 \353\202\230\353\254\264 \354\236\254\355\203\234\355\201\254.py" @@ -0,0 +1,55 @@ +import sys +from collections import deque +input = sys.stdin.readline +n, m, k = map(int, input().split()) + +nutrient = [[5] * n for i in range(n)] +trees = [[deque() for _ in range(n)] for _ in range(n)] +A = [list(map(int, input().split())) for _ in range(n)] + +dx = [-1, 1, 0, 0, -1, -1, 1, 1] +dy = [0, 0, -1, 1, -1, 1, -1, 1] +ans = 0 + + +def spring_and_summer(x, y): + death_tree = 0 + for i in range(len(trees[x][y])): + tree = trees[x][y].popleft() + if tree > nutrient[x][y]: + death_tree += tree + else: + nutrient[x][y] -= tree + trees[x][y].append(tree + 1) + nutrient[x][y] += death_tree // 2 + + +def fall_and_winter(x, y): + for i in trees[x][y]: + if i % 5 == 0: + for j in range(8): + nx = x + dx[j] + ny = y + dy[j] + if nx < 0 or nx >= n or ny < 0 or ny >= n: + continue + trees[nx][ny].appendleft(1) + nutrient[x][y] += A[x][y] + + +for i in range(m): + x, y, age = map(int, input().split()) + trees[x - 1][y - 1].append(age) + +for i in range(k): + for a in range(0, n): + for b in range(0, n): + spring_and_summer(a, b) + for a in range(0, n): + for b in range(0, n): + fall_and_winter(a, b) + +for a in range(0, n): + for b in range(0, n): + ans += len(trees[a][b]) + +print(ans) diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/17070 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 1.py" "b/week-32/\354\235\264\354\244\200\355\230\204/17070 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 1.py" new file mode 100644 index 0000000..38b55cf --- /dev/null +++ "b/week-32/\354\235\264\354\244\200\355\230\204/17070 \355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260 1.py" @@ -0,0 +1,78 @@ +# 파이프 치우기 +import sys +# from collections import deque + +input = sys.stdin.readline + +n = int(input()) +graph = [list(map(int, input().split())) for _ in range(n)] +ans = 0 +dx = [0, 1, 1] +dy = [1, 0, 1] + + +def check_diagonal(x, y): + for i in range(3): + nx = x + dx[i] + ny = y + dy[i] + if nx >= n or ny >= n or graph[nx][ny] == 1: + return False + return True + + +def DFS(x, y, direction): + global ans + if x == y == n - 1: + ans += 1 + return + if direction != 3: + nx = x + dx[0] + ny = y + dy[0] + if not (nx >= n or ny >= n or graph[nx][ny] == 1): + DFS(nx, ny, 2) + if direction != 2: + nx = x + dx[1] + ny = y + dy[1] + if not (nx >= n or ny >= n or graph[nx][ny] == 1): + DFS(nx, ny, 3) + if check_diagonal(x, y): + nx = x + dx[2] + ny = y + dy[2] + DFS(nx, ny, 4) + + +# def BFS(): +# global ans +# q = deque() +# q.append((0, 1, 2)) +# # 2= 가로, 3 = 세로, 4 = 대각선 +# while q: +# x, y, direction = q.popleft() +# if x == y == n - 1: +# ans += 1 +# continue +# # 세로가 아니라면 (가로거나 대각선일떄) +# if direction != 3: +# nx = x + dx[0] +# ny = y + dy[0] +# if not (nx >= n or ny >= n or graph[nx][ny] == 1): +# q.append((nx, ny, 2)) +# # 가로가 아니라면(세로거나 대각선일때) +# if direction != 2: +# nx = x + dx[1] +# ny = y + dy[1] +# if not (nx >= n or ny >= n or graph[nx][ny] == 1): +# q.append((nx, ny, 3)) +# +# if check_diagonal(x, y): +# nx = x + dx[2] +# ny = y + dy[2] +# q.append((nx, ny, 4)) +# +# +# BFS() +if graph[n-1][n-1] == 1: + print(0) +else: + DFS(0, 1, 2) + print(ans) diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/17396 \353\260\261\353\217\204\354\226\264.py" "b/week-32/\354\235\264\354\244\200\355\230\204/17396 \353\260\261\353\217\204\354\226\264.py" new file mode 100644 index 0000000..12c0b4e --- /dev/null +++ "b/week-32/\354\235\264\354\244\200\355\230\204/17396 \353\260\261\353\217\204\354\226\264.py" @@ -0,0 +1,36 @@ +import sys +import heapq + +input = sys.stdin.readline +INF = int(1e10) +n, m = map(int, input().split()) +visited = [True] * n +arr = list(map(int, input().split())) +dist = [INF] * n +graph = [[] for _ in range(n)] +for i in range(n - 1): + if arr[i] == 1: + visited[i] = False + +for i in range(m): + a, b, d = map(int, input().split()) + graph[a].append((b, d)) + graph[b].append((a, d)) +q = [] +if visited[0]: + heapq.heappush(q, (0, 0)) + dist[0] = 0 +while q: + v, d = heapq.heappop(q) + if dist[v] < d: + continue + for i, j in graph[v]: + cost = d + j + if cost < dist[i] and visited[i]: + dist[i] = cost + heapq.heappush(q, (i, cost)) + +if dist[-1] == INF: + print(-1) +else: + print(dist[-1]) diff --git "a/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" "b/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" index e65dc21..9727cea 100644 --- "a/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" +++ "b/week-32/\354\235\264\354\244\200\355\230\204/5972 \355\203\235\353\260\260\353\260\260\354\206\241.py" @@ -13,9 +13,8 @@ graph[b].append((a, d)) q = deque() -q.reverse(); +q.reverse() q.append((1, 0)) -q.ap distance[1] = 0 while q: v, dist = q.popleft()