From 0118d40f6e6025a8494ae044ed8700daa40190ec Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Mon, 18 Dec 2023 17:13:03 +0900 Subject: [PATCH 01/10] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=20=EA=B3=84=EB=8B=A8?= =?UTF-8?q?=EC=98=A4=EB=A5=B4=EA=B8=B0=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/2\354\243\274\354\260\250/2579.py" | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "hyungrak/2\354\243\274\354\260\250/2579.py" diff --git "a/hyungrak/2\354\243\274\354\260\250/2579.py" "b/hyungrak/2\354\243\274\354\260\250/2579.py" new file mode 100644 index 0000000..eef584c --- /dev/null +++ "b/hyungrak/2\354\243\274\354\260\250/2579.py" @@ -0,0 +1,36 @@ +import sys +input = sys.stdin.readline + +n = int(input()) +stair = [0] * 301 +dp = [0] * 301 + +for i in range(n): + stair[i] = int(input()) + +dp[0] = stair[0] +dp[1] = stair[0] + stair[1] +dp[2] = max(stair[0] + stair[2], stair[1] + stair[2]) +for i in range(3, n): + dp[i] = (max(dp[i-3] + stair[i-1] + stair[i], dp[i-2] + stair[i])) + +print(dp[n-1]) + + +#2579 런타임 에러 코드 +# import sys +# input = sys.stdin.readline + +# n = int(input()) +# stair = [] + +# for i in range(n): +# stair.append(int(input())) + +# dp = [stair[0], stair[0] + stair[1], max(stair[0] + stair[2], stair[1] + stair[2])] +# for i in range(3, n): +# dp.append(max(dp[i-3] + stair[i-1] + stair[i], dp[i-2] + stair[i])) + +# print(dp[-1]) + +'''이 코드는 왜 런타임 에러가 뜰까???? ㅜㅜ''' \ No newline at end of file From 664ab84f2de8a1e2b1f63b1ac65951dfa9adcfa4 Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Thu, 28 Dec 2023 12:06:50 +0900 Subject: [PATCH 02/10] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=20=EC=95=94=ED=98=B8?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/2\354\243\274\354\260\250/1759.py" | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "hyungrak/2\354\243\274\354\260\250/1759.py" diff --git "a/hyungrak/2\354\243\274\354\260\250/1759.py" "b/hyungrak/2\354\243\274\354\260\250/1759.py" new file mode 100644 index 0000000..c1b83f4 --- /dev/null +++ "b/hyungrak/2\354\243\274\354\260\250/1759.py" @@ -0,0 +1,24 @@ +from itertools import combinations + + +l, c = map(int, input().split()) + +c_list = list(input().split()) +c_list.sort() +vowel = ['a', 'e', 'i', 'o', 'u'] + +combi_list = list(map(''.join, combinations(c_list, l))) + +for c in combi_list: + cnt_v = 0 + cnt_c = 0 + for char in c: + if char in vowel: + cnt_v += 1 + else: + cnt_c +=1 + if cnt_v > 0 and cnt_c > 1: + print(c) + +'''처음에 모음이 최소 1개 이상 포함되어 있는 것만 출력했는데 계속 틀렸었다. 그래서 자음이 최소 2개 이상 포함되어 있는 것도 체크해서 출력했더니 통과됨. +l이 3 이상인 것이 조건이라 모음 조건만 확인해주면 될 줄 알았음. 반례가 무엇인지는 찾아보아야겠음.''' \ No newline at end of file From 19cb97b86ec0e4ea90f7b789a10c8f7f713d1c8a Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Sat, 6 Jan 2024 15:31:53 +0900 Subject: [PATCH 03/10] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=20=EB=82=B4=EB=A6=AC?= =?UTF-8?q?=EB=A7=89=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1520.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 1520.py diff --git a/1520.py b/1520.py new file mode 100644 index 0000000..4945dc5 --- /dev/null +++ b/1520.py @@ -0,0 +1,58 @@ +# #1260(DFS, BFS 공부하기) +# import sys +# from collections import deque + + +# input = sys.stdin.readline +# n, m, v = map(int, input().split()) +# graph = [[False] * (n + 1) for _ in range(n + 1)] + +# visited_dfs = [False] * (n + 1) +# visited_bfs = [False] * (n + 1) + +# for i in range(m): +# a, b = map(int, input().split()) +# graph[a][b] = graph[b][a] = 1 + +# def dfs(v): +# visited_dfs[v] = True +# print(v, end = " ") +# for i in range(1, n+1): +# if not visited_dfs[i] and graph[v][i] == 1: +# dfs(i) + + + +# def bfs(v): +# queue = deque([v]) +# visited_bfs[v] = True + +# while queue: +# v= queue.popleft() +# print(v, end = " ") +# for i in range(1, n+1): +# if not visited_bfs[i] and graph[v][i] == 1: +# queue.append(i) +# visited_bfs[i] = True + +# dfs(v) +# print() +# bfs(v) + + +#1520 +import sys +input = sys.stdin.readline + +m, n = map(int, input().split()) +maps = [list(map(int, input().split())) for _ in range(m)] + +mem = [[0 for _ in range(n)] for _ in range(m)] #dp를 위한 메모리 +move = [[1, 0], [-1, 0], [0, 1], [0, -1]] #움직임 + +def dfs(a, b): + for i in move: + ma, mb = a + i[0], b + i[1] + if maps[a][b] > maps[ma][mb]: + + From 34061acb9dd89ef96d2f87c39400f1d06e1f51ab Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Sat, 6 Jan 2024 17:09:55 +0900 Subject: [PATCH 04/10] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=EA=B9=8C=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/2\354\243\274\354\260\250/11722.py" | 17 ++++++++++++ .../2\354\243\274\354\260\250/1520.py" | 2 ++ "hyungrak/2\354\243\274\354\260\250/9252.py" | 27 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 "hyungrak/2\354\243\274\354\260\250/11722.py" rename 1520.py => "hyungrak/2\354\243\274\354\260\250/1520.py" (99%) create mode 100644 "hyungrak/2\354\243\274\354\260\250/9252.py" diff --git "a/hyungrak/2\354\243\274\354\260\250/11722.py" "b/hyungrak/2\354\243\274\354\260\250/11722.py" new file mode 100644 index 0000000..3d1d90d --- /dev/null +++ "b/hyungrak/2\354\243\274\354\260\250/11722.py" @@ -0,0 +1,17 @@ +11722 + +import sys + +input = sys.stdin.readline + +n = int(input()) +a = list(map(int, input().split())) +reversed_a = a[::-1] +mem = [1] * n + +for i in range(1, n): + for j in range(i): + if reversed_a[i] > reversed_a[j]: + mem[i] = max(mem[i], mem[j] + 1) + +print(max(mem)) diff --git a/1520.py "b/hyungrak/2\354\243\274\354\260\250/1520.py" similarity index 99% rename from 1520.py rename to "hyungrak/2\354\243\274\354\260\250/1520.py" index 4945dc5..aeb7730 100644 --- a/1520.py +++ "b/hyungrak/2\354\243\274\354\260\250/1520.py" @@ -1,3 +1,5 @@ +1520 + # #1260(DFS, BFS 공부하기) # import sys # from collections import deque diff --git "a/hyungrak/2\354\243\274\354\260\250/9252.py" "b/hyungrak/2\354\243\274\354\260\250/9252.py" new file mode 100644 index 0000000..9fc0dc1 --- /dev/null +++ "b/hyungrak/2\354\243\274\354\260\250/9252.py" @@ -0,0 +1,27 @@ +9252 + +import sys + +input = sys.stdin.readline + +str_a = input().rstrip() +str_b = input().rstrip() +la = len(str_a) +lb = len(str_b) +mem = [['' for _ in range(la+1)] for _ in range(lb+1)] #범위를 딱맞게 했더니 index error가 남 +'''dp 표를 이용함. ''' + +for i in range(1, lb+1): + for j in range(1, la+1): + if str_a[j-1] == str_b[i-1]: + mem[i][j] = mem[i-1][j-1] + str_a[j-1] + else: + if len(mem[i-1][j]) >= len(mem[i][j-1]): + mem[i][j] = mem[i-1][j] + else: + mem[i][j] = mem[i][j-1] + +ans = mem[-1][-1] #이거를 해주고 안해주고 차이에서 시간초과가 나냐 안나나가 결정됨 ㅇㅅㅇ.. 왤까?? + +print(len(ans), ans, sep="\n") + From 63bd5e69df10e3051306f953aa05c47e99d36a51 Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Tue, 9 Jan 2024 00:14:33 +0900 Subject: [PATCH 05/10] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EC=8A=A4=ED=8B=B0?= =?UTF-8?q?=EC=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/3\354\243\274\354\260\250/9465.py" | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "hyungrak/3\354\243\274\354\260\250/9465.py" diff --git "a/hyungrak/3\354\243\274\354\260\250/9465.py" "b/hyungrak/3\354\243\274\354\260\250/9465.py" new file mode 100644 index 0000000..7cb4daf --- /dev/null +++ "b/hyungrak/3\354\243\274\354\260\250/9465.py" @@ -0,0 +1,27 @@ +import sys + +input = sys.stdin.readline + +t = int(input()) +ans = [] + +def dp (n, sticker): + if n == 1: + return max(sticker[0][0], sticker[1][0]) + elif n == 2: + return max(sticker[0][1] + sticker[1][0], sticker[1][1] + sticker[0][0]) + else: + sticker[0][1] += sticker[1][0] + sticker[1][1] += sticker[0][0] + + for i in range(2, n): + sticker[0][i] += max(sticker[1][i-1], sticker[1][i-2]) + sticker[1][i] += max(sticker[0][i-1], sticker[0][i-2]) + return max(sticker[0][n-1], sticker[1][n-1]) + +for i in range(t): + n = int(input()) + sticker = [list(map(int, input().split())) for _ in range(2)] + ans.append(dp(n, sticker)) + +print(*ans, sep="\n") \ No newline at end of file From e4e64395960bbd84908ba5b9266cfe231c12c929 Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Tue, 9 Jan 2024 17:50:59 +0900 Subject: [PATCH 06/10] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=20=EC=9A=94=EC=86=8C=EC=9D=98=20=EA=B0=9C=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/3\354\243\274\354\260\250/11724.py" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "hyungrak/3\354\243\274\354\260\250/11724.py" diff --git "a/hyungrak/3\354\243\274\354\260\250/11724.py" "b/hyungrak/3\354\243\274\354\260\250/11724.py" new file mode 100644 index 0000000..334073d --- /dev/null +++ "b/hyungrak/3\354\243\274\354\260\250/11724.py" @@ -0,0 +1,35 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +n, m = map(int, input().split()) +graph = [[False] * (n+1) for _ in range(n+1)] +visited = [False] * (n+1) +cnt = 0 +visited[0] = True + +for i in range(m): + a, b = map(int, input().split()) + graph[a][b] = graph[b][a] = 1 + +def bfs(v): + queue = deque([v]) + visited[v] = True + + while queue: + v = queue.popleft() + for i in range(1, n+1): + if not visited[i] and graph[v][i] == 1: + queue.append(i) + visited[i] = True + return 0 + +for i in range(1, n+1): + if visited[i] == False: + bfs(i) + cnt += 1 + else: + continue + +print(cnt) \ No newline at end of file From a7c240b34f8c01f4bd2a1c4b25c3e61bc25b6c0e Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Wed, 10 Jan 2024 14:29:41 +0900 Subject: [PATCH 07/10] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EB=AF=B8=EB=A1=9C?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/3\354\243\274\354\260\250/2178.py" | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "hyungrak/3\354\243\274\354\260\250/2178.py" diff --git "a/hyungrak/3\354\243\274\354\260\250/2178.py" "b/hyungrak/3\354\243\274\354\260\250/2178.py" new file mode 100644 index 0000000..fb50a02 --- /dev/null +++ "b/hyungrak/3\354\243\274\354\260\250/2178.py" @@ -0,0 +1,28 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +n, m = map(int, input().split()) +miro = [list(map(int, ' '.join(input().split()))) for i in range(n)] +move_a = [1, -1, 0, 0] +move_b = [0, 0, 1, -1] + +def bfs(v): + queue = deque([v]) + while queue: + v = queue.popleft() + for i in range(4): + ma = v[0] + move_a[i] + mb = v[1] + move_b[i] + if ma < 0 or mb < 0 or ma >= n or mb >= m: + continue + else: + if miro[ma][mb] == 1: + miro[ma][mb] = miro[v[0]][v[1]] + 1 + queue.append([ma, mb]) + + return miro[n-1][m-1] + +print(bfs([0, 0])) + From b48a2fe7180ecba8dde72b1c3dec7430c9d656c7 Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Fri, 12 Jan 2024 06:11:41 +0900 Subject: [PATCH 08/10] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=ED=86=A0=EB=A7=88?= =?UTF-8?q?=ED=86=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/3\354\243\274\354\260\250/7576.py" | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "hyungrak/3\354\243\274\354\260\250/7576.py" diff --git "a/hyungrak/3\354\243\274\354\260\250/7576.py" "b/hyungrak/3\354\243\274\354\260\250/7576.py" new file mode 100644 index 0000000..f7024ed --- /dev/null +++ "b/hyungrak/3\354\243\274\354\260\250/7576.py" @@ -0,0 +1,38 @@ +import sys +input = sys.stdin.readline +from collections import deque + +m, n = map(int, input().split()) +tomato = [list(map(int, input().split())) for _ in range(n)] +queue = deque([]) +x = [-1, 1, 0, 0] +y = [0, 0, -1, 1] +ans = 0 + +for i in range(n): + for j in range(m): + if tomato[i][j] == 1: + queue.append([i, j]) + + +while queue: + k = queue.popleft() + for i in range(4): + dx = k[0] + x[i] + dy = k[1] + y[i] + if dx < 0 or dy < 0 or dx >= n or dy >= m: + continue + elif tomato[dx][dy] == 0: + tomato[dx][dy] = tomato[k[0]][k[1]] + 1 + queue.append([dx, dy]) + +for i in range(n): + for j in range(m): + if tomato[i][j] == 0: + print(-1) + exit(0) + ans = max(ans, tomato[i][j]) + +print(ans-1) + + From d090721e20dffd5df5e76ffa7aa91d9fc57b94a9 Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Sun, 14 Jan 2024 14:00:50 +0900 Subject: [PATCH 09/10] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8=20=EB=82=B4=EB=A6=AC?= =?UTF-8?q?=EB=A7=89=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/3\354\243\274\354\260\250/1520.py" | 105 +++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "hyungrak/3\354\243\274\354\260\250/1520.py" diff --git "a/hyungrak/3\354\243\274\354\260\250/1520.py" "b/hyungrak/3\354\243\274\354\260\250/1520.py" new file mode 100644 index 0000000..176a9a8 --- /dev/null +++ "b/hyungrak/3\354\243\274\354\260\250/1520.py" @@ -0,0 +1,105 @@ +1520 + +# #1260(DFS, BFS 공부하기) +# import sys +# from collections import deque + + +# input = sys.stdin.readline +# n, m, v = map(int, input().split()) +# graph = [[False] * (n + 1) for _ in range(n + 1)] + +# visited_dfs = [False] * (n + 1) +# visited_bfs = [False] * (n + 1) + +# for i in range(m): +# a, b = map(int, input().split()) +# graph[a][b] = graph[b][a] = 1 + +# def dfs(v): +# visited_dfs[v] = True +# print(v, end = " ") +# for i in range(1, n+1): +# if not visited_dfs[i] and graph[v][i] == 1: +# dfs(i) + + + +# def bfs(v): +# queue = deque([v]) +# visited_bfs[v] = True + +# while queue: +# v= queue.popleft() +# print(v, end = " ") +# for i in range(1, n+1): +# if not visited_bfs[i] and graph[v][i] == 1: +# queue.append(i) +# visited_bfs[i] = True + +# dfs(v) +# print() +# bfs(v) + + +# #1520 +# import sys +# from collections import deque +# input = sys.stdin.readline + +# m, n = map(int, input().split()) +# maps = [list(map(int, input().split())) for _ in range(m)] + +# move_a = [-1, 1, 0, 0] +# move_b = [0, 0, -1, 1] + + +# def dfs(v): +# stack = deque([v]) +# cnt = 0 +# while stack: +# v = stack.pop() +# for i in range(4): +# ma = v[0] + move_a[i] +# mb = v[1] + move_b[i] +# if ma < 0 or mb < 0 or ma >= m or mb >= n: +# continue +# else: +# if maps[ma][mb] < maps[v[0]][v[1]]: +# stack.append([ma, mb]) +# if ma == m-1 and mb == n-1: +# stack.pop() +# cnt += 1 +# print(cnt) + +# dfs([0, 0]) + +# '''시간 초과가 나오는 코드 모든 경로를 다 탐색해서 그런듯 ㅜㅜ''' + + +#1520 +'''이 풀이는 다른 사람들이 일반적으로 푼 풀이랑 똑같은 듯. dfs에 dp까지 적용을 해서 푸는 것.''' +import sys +input = sys.stdin.readline + +m, n = map(int, input().split()) +maps = [list(map(int, input().split())) for _ in range(m)] +dp = [[-1] * n for _ in range(m)] +move_a = [-1, 1, 0, 0] +move_b = [0, 0, -1, 1] + +def dfs_dp(v): + if v[0] == m - 1 and v[1] == n - 1: #목적지는 1로 + return 1 + if dp[v[0]][v[1]] != -1: #이미 방문한 곳이면 그 값 반환 + return dp[v[0]][v[1]] + dp[v[0]][v[1]] = 0 #방문처리 후에 뒤로가는 과정에서 그 값 추가 + for i in range(4): + ma = v[0] + move_a[i] + mb = v[1] + move_b[i] + if 0 <= ma < m and 0 <= mb < n: + if maps[ma][mb] < maps[v[0]][v[1]]: + dp[v[0]][v[1]] += dfs_dp([ma, mb]) #재귀호출 4개 방향으로 해서 해당위치 dp값 계속 추가 + return dp[v[0]][v[1]] #4개 방향을 모두 돌아 탐색이 끝나면 dp[v[0]][v[1]]값 리턴해서 부모 노드의 4개 방향 탐색 중 하나 완료 + +print(dfs_dp([0, 0])) From e2def3a065748aa3bec729e70d18d29a1f1a134f Mon Sep 17 00:00:00 2001 From: RAKRAK21 Date: Mon, 15 Jan 2024 21:20:54 +0900 Subject: [PATCH 10/10] =?UTF-8?q?4=EC=A3=BC=EC=B0=A8=20=EC=98=A4=EB=A5=B4?= =?UTF-8?q?=EB=A7=89=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "hyungrak/4\354\243\274\354\260\250/11057.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "hyungrak/4\354\243\274\354\260\250/11057.py" diff --git "a/hyungrak/4\354\243\274\354\260\250/11057.py" "b/hyungrak/4\354\243\274\354\260\250/11057.py" new file mode 100644 index 0000000..9cc9151 --- /dev/null +++ "b/hyungrak/4\354\243\274\354\260\250/11057.py" @@ -0,0 +1,12 @@ +import sys +input = sys.stdin.readline + +n = int(input()) +dp = [[1] * 10 for _ in range(n)] + +for i in range(1, n): + for j in range(1, 10): + dp[i][j] = dp[i-1][j] + dp[i][j-1] + +ans = sum(dp[n-1]) % 10007 +print(ans) \ No newline at end of file