Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions week-30/이준현/15652 N과 M 2.py
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 30 additions & 0 deletions week-30/이준현/2096 내려가기 2.py
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ def DFS(x, y):
DFS(nx, ny)
graph[x][y] = False


DFS(1, 1)
print(ans)
print(ans)
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions week-32/이준현/16235 나무 재태크.py
Original file line number Diff line number Diff line change
@@ -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)
78 changes: 78 additions & 0 deletions week-32/이준현/17070 파이프 옮기기 1.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions week-32/이준현/17396 백도어.py
Original file line number Diff line number Diff line change
@@ -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])
29 changes: 29 additions & 0 deletions week-32/이준현/5972 택배배송.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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))
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])