From 1f5a3faa377d134ecdb7c83b309711db0d904117 Mon Sep 17 00:00:00 2001 From: oxhwixo Date: Tue, 28 Mar 2023 00:50:22 +0900 Subject: [PATCH 1/3] =?UTF-8?q?30=EC=A3=BC=EC=B0=A8=EC=8A=B9=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../14712.py" | 30 +++++++++++ .../1535.py" | 22 ++++++++ .../1699.py" | 14 +++++ .../22233.py" | 12 +++++ .../2565.py" | 17 ++++++ .../9333.py" | 52 +++++++++++++++++++ .../10974.py" | 19 +++++++ .../2961.py" | 28 ++++++++++ .../5568.py" | 25 +++++++++ 9 files changed, 219 insertions(+) create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/14712.py" create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/1535.py" create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/1699.py" create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/22233.py" create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/2565.py" create mode 100644 "week-29/\354\236\245\354\212\271\354\235\264/9333.py" create mode 100644 "week-30/\354\236\245\354\212\271\354\235\264/10974.py" create mode 100644 "week-30/\354\236\245\354\212\271\354\235\264/2961.py" create mode 100644 "week-30/\354\236\245\354\212\271\354\235\264/5568.py" diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/14712.py" "b/week-29/\354\236\245\354\212\271\354\235\264/14712.py" new file mode 100644 index 0000000..465b57d --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/14712.py" @@ -0,0 +1,30 @@ +# 14712 넴모넴모 +# 실버 1 + +# 모든 맵 탐색하면서 넴모가 생기는 경우 빼주기 + +n, m = map(int, input().split()) + +graph = [[0] * (m + 1) for _ in range(n + 1)] +ans = 0 + +def dfs(cnt): + global ans + + if cnt == n * m: + ans += 1 + return + + # 행은 몫으로 열은 나머지연산으로 구함 + # (1, 1) ~ (n, m) + x = cnt // m + 1 # 행 + y = cnt % m + 1 # 열 + + dfs(cnt + 1) + if graph[x - 1][y] == 0 or graph[x][y - 1] == 0 or graph[x - 1][y - 1] == 0: + graph[x][y] = 1 + dfs(cnt + 1) + graph[x][y] = 0 + +dfs(0) +print(ans) \ No newline at end of file diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/1535.py" "b/week-29/\354\236\245\354\212\271\354\235\264/1535.py" new file mode 100644 index 0000000..fb02790 --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/1535.py" @@ -0,0 +1,22 @@ +# 1535 안녕 +# 실버 2 + +# 냅색 알고리즘 + +import sys +input = sys.stdin.readline + + +N = int(input()) +L = [0] + list(map(int, input().split())) # Lost +P = [0] + list(map(int, input().split())) # Pleasure +dp = [[0] * 101 for _ in range(N + 1)] + +for i in range(1, N+1): + for j in range(1, 101): # 체력은 1 ~ 100 + if L[i] <= j: + dp[i][j] = max(dp[i-1][j], dp[i-1][j-L[i]] + P[i]) + else: + dp[i][j] = dp[i-1][j] + +print(dp[N][99]) \ No newline at end of file diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/1699.py" "b/week-29/\354\236\245\354\212\271\354\235\264/1699.py" new file mode 100644 index 0000000..25e1846 --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/1699.py" @@ -0,0 +1,14 @@ +# 1699 제곱수의 합 +# 실버 2 + +n = int(input()) + +d = [i for i in range(n + 1)] + +for i in range(1, n + 1): + for j in range(1, i): + if j**2 > i: + break + d[i] = min(d[i], d[i - j**2] + 1) + +print(d[n]) \ No newline at end of file diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/22233.py" "b/week-29/\354\236\245\354\212\271\354\235\264/22233.py" new file mode 100644 index 0000000..c7ca987 --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/22233.py" @@ -0,0 +1,12 @@ +# 22232 가희와 키워드 +# 실버 2 + +import sys +input = sys.stdin.readline + +n, m = map(int, input().split()) +keywords = set([input().strip() for _ in range(n)]) + +for _ in range(m): + keywords -= set(list(input().strip().split(","))) + print(len(keywords)) \ No newline at end of file diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/2565.py" "b/week-29/\354\236\245\354\212\271\354\235\264/2565.py" new file mode 100644 index 0000000..29cf10d --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/2565.py" @@ -0,0 +1,17 @@ +# 2565 전깃줄 +# 골드 5 + +import sys + +input = sys.stdin.readline + +n = int(input()) +data = sorted(list(map(int, input().split())) for _ in range(n)) + +d = [1] * n +for i in range(n): + for j in range(i): + if data[i][1] > data[j][1]: + d[i] = max(d[i], d[j] + 1) + +print(n - max(d)) \ No newline at end of file diff --git "a/week-29/\354\236\245\354\212\271\354\235\264/9333.py" "b/week-29/\354\236\245\354\212\271\354\235\264/9333.py" new file mode 100644 index 0000000..afce424 --- /dev/null +++ "b/week-29/\354\236\245\354\212\271\354\235\264/9333.py" @@ -0,0 +1,52 @@ +# 9333 돈 갚기 +# 실버 1 + +import sys +input = sys.stdin.readline + +n = int(input()) + +for _ in range(n): + r, b, m = map(float, input().split()) + + count = 0 + + while b > 0: + count += 1 + if count > 1200: + count = -1 + break + + b += (b * r) / 100 + b = round(b, 8) + if (b * 1000) % 10 == 5: + b += 0.001 + b = round(b, 2) + b -= m + + print("impossible" if count == -1 else count) + +# def my_round(number): +# number = round(round(number, 8), 3) + +# check = (number * 1000) % 100 + +# if check >= 50: +# return round(number + 0.001, 2) +# else: +# return round(number, 2) + +# for _ in range(n): +# r, b, m = map(float, input().split()) +# count = 0 + +# while b > 0: +# if count > 1200: +# count = -1 +# break + +# interest = my_round(b * (r / 100)) +# b = round(round(b + interest - m, 8), 2) +# count += 1 + +# print("impossible" if count == -1 else count) diff --git "a/week-30/\354\236\245\354\212\271\354\235\264/10974.py" "b/week-30/\354\236\245\354\212\271\354\235\264/10974.py" new file mode 100644 index 0000000..0b5ca89 --- /dev/null +++ "b/week-30/\354\236\245\354\212\271\354\235\264/10974.py" @@ -0,0 +1,19 @@ +# 10974 모든 순열 +# 실버 3 + +n = int(input()) +ans = [] +def bt(depth): + if depth == n: + for i in range(n): + print(ans[i], end = ' ') + print() + return + + for i in range(1, n + 1): + if i not in ans: + ans.append(i) + bt(depth + 1) + ans.remove(i) + +bt(0) \ No newline at end of file diff --git "a/week-30/\354\236\245\354\212\271\354\235\264/2961.py" "b/week-30/\354\236\245\354\212\271\354\235\264/2961.py" new file mode 100644 index 0000000..8cad2e8 --- /dev/null +++ "b/week-30/\354\236\245\354\212\271\354\235\264/2961.py" @@ -0,0 +1,28 @@ +# 2961 도영이가 만든 맛있는 음식 +# 실버 2 + +import sys +input = sys.stdin.readline + +n = int(input()) +foods = [list(map(int, input().split(" "))) for _ in range(n)] +ans = [] +temp_idx = [] + +def bt(num, depth): + if depth == n: + return + for i in range(num, n): + temp_idx.append(i) + mult = 1 + add = 0 + print(temp_idx) + for j in temp_idx: + mult *= foods[j][0] + add += foods[j][1] + ans.append(abs(mult-add)) + bt(i + 1, depth + 1) + temp_idx.remove(i) + +bt(0, 0) +print(min(ans)) \ No newline at end of file diff --git "a/week-30/\354\236\245\354\212\271\354\235\264/5568.py" "b/week-30/\354\236\245\354\212\271\354\235\264/5568.py" new file mode 100644 index 0000000..35b41b5 --- /dev/null +++ "b/week-30/\354\236\245\354\212\271\354\235\264/5568.py" @@ -0,0 +1,25 @@ +# 5568 카드 놓기 +# 실버 4 + +n = int(input()) +k = int(input()) +cards = [int(input()) for _ in range(n)] +temp = [] +ans = set() + +def bt(depth): + if depth == k: + new_num = "" + for i in range(k): + new_num += str(cards[temp[i]]) + ans.add(int(new_num)) + return + + for i in range(n): + if i not in temp: + temp.append(i) + bt(depth + 1) + temp.remove(i) + +bt(0) +print(len(ans)) From a6c1f553ce882876a5a56a325e843491a25c74dc Mon Sep 17 00:00:00 2001 From: oxhwixo Date: Tue, 11 Apr 2023 20:59:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?31=EC=8A=B9=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../16235.py" | 53 ++++++++++++++++ .../17070.py" | 39 ++++++++++++ .../17396.py" | 32 ++++++++++ .../21610.py" | 61 +++++++++++++++++++ .../5972.py" | 28 +++++++++ .../6593.py" | 50 +++++++++++++++ 6 files changed, 263 insertions(+) create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/16235.py" create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/17070.py" create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/17396.py" create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/21610.py" create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/5972.py" create mode 100644 "week-31/\354\236\245\354\212\271\354\235\264/6593.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/16235.py" "b/week-31/\354\236\245\354\212\271\354\235\264/16235.py" new file mode 100644 index 0000000..60e9011 --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/16235.py" @@ -0,0 +1,53 @@ +# 16235 나무 재테크 + +import sys +from collections import deque +input = sys.stdin.readline + +dx = [-1, -1, -1, 0, 0, 1, 1, 1] +dy = [-1, 0, 1, -1, 1, -1, 0, 1] + +N, M, K = map(int, input().split()) +arr = [[5]*N for _ in range(N)] +s2d2 = [] +tree = [[deque() for _ in range(N)] for _ in range(N)] +for _ in range(N): + s2d2.append(list(map(int, input().split()))) +for _ in range(M): + x, y, z = map(int, input().split()) + tree[x-1][y-1].append(z) + +while K > 0: + # 봄 + for i in range(N): + for j in range(N): + t_len = len(tree[i][j]) + for k in range(t_len): + if arr[i][j] >= tree[i][j][k]: + arr[i][j] -= tree[i][j][k] + tree[i][j][k] += 1 + else: + # 여름 + for _ in range(k, t_len): + arr[i][j] += tree[i][j].pop() // 2 + break + + # 가을 + for i in range(N): + for j in range(N): + for z in tree[i][j]: + if z % 5 == 0: + for l in range(8): + nx = i + dx[l] + ny = j + dy[l] + if 0 <= nx < N and 0 <= ny < N: + tree[nx][ny].appendleft(1) + #겨울 + arr[i][j] += s2d2[i][j] + K -= 1 + +result = 0 +for i in range(N): + for j in range(N): + result += len(tree[i][j]) +print(result) \ No newline at end of file diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/17070.py" "b/week-31/\354\236\245\354\212\271\354\235\264/17070.py" new file mode 100644 index 0000000..b82716d --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/17070.py" @@ -0,0 +1,39 @@ +# 17070 파이프 옮기기1 +# 골드5 + +import sys +input = sys.stdin.readline + +n = int(input()) +graph = [list(map(int, input().split())) for _ in range(n)] +visited = [[False] * n for _ in range(n)] + +ans = 0 + +def dfs(x, y, code): # code = 0:가로 1:세로 2:대각선 + global ans + if x == n - 1 and y == n - 1: + ans += 1 + return + + if code == 0 or code == 2: + ny = y + 1 + if ny < n and graph[x][ny] == 0: + dfs(x, ny, 0) + if code == 1 or code == 2: + nx = x + 1 + if nx < n and graph[nx][y] == 0: + dfs(nx, y, 1) + + nx = x + 1 + ny = y + 1 + if nx < n and ny < n and graph[nx][ny] == 0 and graph[nx - 1][ny] == 0 and graph[nx][ny - 1] == 0: + dfs(nx, ny, 2) + + +if graph[n-1][n-1] == 1: + print(0) +else: + dfs(0, 1, 0) + print(ans) + diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/17396.py" "b/week-31/\354\236\245\354\212\271\354\235\264/17396.py" new file mode 100644 index 0000000..cc1b8ad --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/17396.py" @@ -0,0 +1,32 @@ +# 17369 백도어 +# 골드 5 + +import sys +import heapq +input = sys.stdin.readline + +n, m = map(int, input().split()) +graph = [[] for _ in range(n)] +distance = [10000000001] * n +view = list(map(int, input().split())) + +for _ in range(m): + a, b, c = map(int, input().split()) + graph[a].append((b, c)) + graph[b].append((a, c)) + +q = [] +distance[0] = 0 +heapq.heappush(q, (0, 0)) # dist, cost +while q: + now, dist = heapq.heappop(q) + if distance[now] < dist: + continue + for i in graph[now]: + cost = dist + i[1] + if cost < distance[i[0]]: + distance[i[0]] = cost + if view[i[0]] != 1 or (view[i[0]] and i[0] == n - 1): + heapq.heappush(q, (i[0], cost)) + +print(distance[n - 1] if distance[n - 1] != 10000000001 else -1) diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/21610.py" "b/week-31/\354\236\245\354\212\271\354\235\264/21610.py" new file mode 100644 index 0000000..60c3ae6 --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/21610.py" @@ -0,0 +1,61 @@ +# 21610 마법사 상어와 비바라기 +# 골드5 + +import sys +from collections import deque + +input = sys.stdin.readline +n, m = map(int, input().split()) +graph = [list(map(int, input().split())) for _ in range(n)] +dir_move = [list(map(int, input().split())) for _ in range(m)] +dx = 0, -1, -1, -1, 0, 1, 1, 1 +dy = -1, -1, 0, 1, 1, 1, 0, -1 +cloud = [(n - 1, 0), (n - 1, 1), (n - 2, 0), (n - 2, 1)] +cloud = deque(cloud) + + +def move_rain(dir, dist): + global n + size = len(cloud) + for _ in range(size): + x, y = cloud.popleft() + nx = (x + dx[dir] * dist) % n + ny = (y + dy[dir] * dist) % n + if 0 > nx: + nx += n + if 0 > ny: + ny += n + cloud.append((nx, ny)) + # 구름 사라진 자리 + visited[nx][ny] = True + graph[nx][ny] += 1 + + +def dup(): + while cloud: + # 대각선 검사 + x, y = cloud.popleft() + for i in range(1, 8, 2): + nx = x + dx[i] + ny = y + dy[i] + if 0 <= nx < n and 0 <= ny < n and graph[nx][ny] > 0: + graph[x][y] += 1 + + +for dir, dist in dir_move: + visited = [[False] * n for _ in range(n)] + # 구름 이동 후 비 + move_rain(dir - 1, dist) + # 물 복사 + dup() + # 구름 생성 + for i in range(n): + for j in range(n): + if graph[i][j] >= 2 and not visited[i][j]: + cloud.append((i, j)) + graph[i][j] -= 2 +answer = 0 +for i in range(n): + for j in range(n): + answer += graph[i][j] +print(answer) \ No newline at end of file diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/5972.py" "b/week-31/\354\236\245\354\212\271\354\235\264/5972.py" new file mode 100644 index 0000000..187e26c --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/5972.py" @@ -0,0 +1,28 @@ +# 5972 택배 배송 +# 골드 5 + +import sys +import heapq +input = sys.stdin.readline + +n, m = map(int, input().split()) +graph = [[] for _ in range(n + 1)] +distance = [1e9] * (n + 1) +for _ in range(m): + a, b, cost = map(int, input().split()) + graph[a].append((b, cost)) + graph[b].append((a, cost)) +q = [] +heapq.heappush(q, (1, 0)) # (node, cost) +distance[1] = 0 +while q: + now, dist = heapq.heappop(q) + if distance[now] < dist: + continue + for visit_node in graph[now]: + cost = dist + visit_node[1] + if distance[visit_node[0]] > cost: + distance[visit_node[0]] = cost + heapq.heappush(q, (visit_node[0], distance[visit_node[0]])) + +print(distance[n]) \ No newline at end of file diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/6593.py" "b/week-31/\354\236\245\354\212\271\354\235\264/6593.py" new file mode 100644 index 0000000..8b7965c --- /dev/null +++ "b/week-31/\354\236\245\354\212\271\354\235\264/6593.py" @@ -0,0 +1,50 @@ +# 6593 상범빌딩 + +import sys +from collections import deque +input = sys.stdin.readline + +dx = [0, 0, 0, 0, -1, 1] +dy = [0, 0, -1, 1, 0, 0] +dz = [1, -1, 0, 0, 0, 0] + +def bfs(z, x, y): + queue = deque([(z, x, y)]) + + while queue: + z, x, y = queue.popleft() + + for i in range(6): + nz = dz[i] + z + nx = dx[i] + x + ny = dy[i] + y + + if 0 <= nx < r and 0 <= ny < c and 0 <= nz < l and visited[nz][nx][ny] == 0 and not graph[nz][nx][ny] == '#': + visited[nz][nx][ny] = visited[z][x][y] + 1 + if graph[nz][nx][ny] == 'E': + print(f"Escaped in {visited[nz][nx][ny]} minute(s).") + return + queue.append((nz, nx, ny)) + + print("Trapped!") + + +while True: + l, r, c = map(int, input().split()) + + if l == 0 and r == 0 and c == 0: + break + + visited = [[[0] * c for _ in range(r)] for _ in range(l)] + graph = [] + for i in range(l): + floor_temp = [] + for j in range(r): + temp = list(input().strip()) + if 'S' in temp: + s_index = [i, j, temp.index('S')] + floor_temp.append(temp) + graph.append(floor_temp) + input() + + bfs(s_index[0], s_index[1], s_index[2]) From f62a1e464801e3793a63da405ac0de98ca3e57fa Mon Sep 17 00:00:00 2001 From: oxhwixo Date: Tue, 11 Apr 2023 21:00:49 +0900 Subject: [PATCH 3/3] 32week --- .../\354\236\245\354\212\271\354\235\264/16235.py" | 0 .../\354\236\245\354\212\271\354\235\264/17070.py" | 0 .../\354\236\245\354\212\271\354\235\264/17396.py" | 0 .../\354\236\245\354\212\271\354\235\264/21610.py" | 0 .../\354\236\245\354\212\271\354\235\264/5972.py" | 0 .../\354\236\245\354\212\271\354\235\264/6593.py" | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename "week-31/\354\236\245\354\212\271\354\235\264/16235.py" => "week-32/\354\236\245\354\212\271\354\235\264/16235.py" (100%) rename "week-31/\354\236\245\354\212\271\354\235\264/17070.py" => "week-32/\354\236\245\354\212\271\354\235\264/17070.py" (100%) rename "week-31/\354\236\245\354\212\271\354\235\264/17396.py" => "week-32/\354\236\245\354\212\271\354\235\264/17396.py" (100%) rename "week-31/\354\236\245\354\212\271\354\235\264/21610.py" => "week-32/\354\236\245\354\212\271\354\235\264/21610.py" (100%) rename "week-31/\354\236\245\354\212\271\354\235\264/5972.py" => "week-32/\354\236\245\354\212\271\354\235\264/5972.py" (100%) rename "week-31/\354\236\245\354\212\271\354\235\264/6593.py" => "week-32/\354\236\245\354\212\271\354\235\264/6593.py" (100%) diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/16235.py" "b/week-32/\354\236\245\354\212\271\354\235\264/16235.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/16235.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/16235.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/17070.py" "b/week-32/\354\236\245\354\212\271\354\235\264/17070.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/17070.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/17070.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/17396.py" "b/week-32/\354\236\245\354\212\271\354\235\264/17396.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/17396.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/17396.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/21610.py" "b/week-32/\354\236\245\354\212\271\354\235\264/21610.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/21610.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/21610.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/5972.py" "b/week-32/\354\236\245\354\212\271\354\235\264/5972.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/5972.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/5972.py" diff --git "a/week-31/\354\236\245\354\212\271\354\235\264/6593.py" "b/week-32/\354\236\245\354\212\271\354\235\264/6593.py" similarity index 100% rename from "week-31/\354\236\245\354\212\271\354\235\264/6593.py" rename to "week-32/\354\236\245\354\212\271\354\235\264/6593.py"