From ee548e979ad43439d8e64e2fbe74d65a2d8a3a3f Mon Sep 17 00:00:00 2001 From: Hongjoo Date: Sun, 1 Jun 2025 02:28:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[PGS]#12914.=EB=A9=80=EB=A6=AC=EB=9B=B0?= =?UTF-8?q?=EA=B8=B0/lv2/=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ttps://school.programmers.co.kr/learn/courses/30/lessons/12914?language=python3 --- ...00\353\246\254\353\233\260\352\270\260.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "Hongjoo/lv2/\353\251\200\353\246\254\353\233\260\352\270\260.py" diff --git "a/Hongjoo/lv2/\353\251\200\353\246\254\353\233\260\352\270\260.py" "b/Hongjoo/lv2/\353\251\200\353\246\254\353\233\260\352\270\260.py" new file mode 100644 index 0000000..3515d57 --- /dev/null +++ "b/Hongjoo/lv2/\353\251\200\353\246\254\353\233\260\352\270\260.py" @@ -0,0 +1,22 @@ +answer = 0 +def solution(n): + + def backtracking(path,lv): + # 재귀 종료 + global answer + if lv >= len(path): + if sum(path)==n : + answer += 1 + # print(f"{lv} : {path} >{answer}") + return 0 + #자식 노드 이동 + for x in [1,2] : + if sum(path) + x <= n : + path[lv] = x + backtracking(path , lv+1) + # backtracking + path[lv] = 0 + + for m in range(1,n+1) : + backtracking([0]*m , 0) + return answer%1234567 \ No newline at end of file From 271191fc5d2e56f47f2e33a1138c01a85aaaf072 Mon Sep 17 00:00:00 2001 From: Hongjoo Date: Sun, 1 Jun 2025 02:28:52 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[BOJ]#11559.=20=EB=BF=8C=EC=9A=94=EB=BF=8C?= =?UTF-8?q?=EC=9A=94/=EA=B3=A8=EB=93=9C4/3hour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/11559 --- ...14\354\232\224\353\277\214\354\232\224.py" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "Hongjoo/\353\260\261\354\244\200/\353\277\214\354\232\224\353\277\214\354\232\224.py" diff --git "a/Hongjoo/\353\260\261\354\244\200/\353\277\214\354\232\224\353\277\214\354\232\224.py" "b/Hongjoo/\353\260\261\354\244\200/\353\277\214\354\232\224\353\277\214\354\232\224.py" new file mode 100644 index 0000000..42c9802 --- /dev/null +++ "b/Hongjoo/\353\260\261\354\244\200/\353\277\214\354\232\224\353\277\214\354\232\224.py" @@ -0,0 +1,90 @@ +""" +20.19 +https://www.acmicpc.net/problem/11559 +BOJ.#11559_Gold4 + +#problem +- goal) 연쇄 "연속" 횟수 구하기 +[condition] +- 1연쇄 : 해당 turn 에서 상하좌우 4개 연결 -> 삭제 +- 삭제 후 위에 있는 element 는 하강 + +- 입력: 현 filed 상황(12x6) + - (빈공간) / R, G, B, P, Y + - 빈공간 : 0 + - 색상 : R,G, B, P, Y = 1,2,3,4,5 +[flow] # BFS +1. 상하좌우 연쇄 확인 +- 연쇄 확인 +- 삭제 +- 연쇄 횟수 증가 + +""" +import sys +from collections import deque +input = sys.stdin.readline +#1. field 현황 리스트에 담기 +field = [list(input())[:-1] for _ in range(12)] + +#2. bfs +dy = [-1,1,0,0] +dx =[0,0,-1,1] + + +def refine_field(x) : # 중간 빈자리 + stack = deque() + #1.아레=> 위로 스택에 뿌요뿌요 순서대로 축척하기 + for ny in range(11, -1,-1): + if field[ny][x] != ".": + stack.append(field[ny][x]) + for ny in range(11, -1, -1) : + if stack : + field[ny][x] = stack.popleft() + else : + field[ny][x] = "." + +# 연쇄 확인 및 터짐 +def bfs(sy,sx): + q = deque() + q.append([sy,sx]) + pop_positions = [[sy,sx]] + cur_color = field[sy][sx] + visited.append([sy,sx]) + while q : + cy,cx = q.popleft() + for d in range(4): + ny ,nx = cy + dy[d] ,cx + dx[d] + # 같은 색상 -> 삭제 등록하기 + if 0<= ny<12 and 0<= nx < 6 and [ny,nx] not in visited and field[ny][nx] == cur_color : + q.append([ny,nx]) + pop_positions.append([ny,nx]) + visited.append([ny,nx]) + + #2) 터짐 확인 + if len(pop_positions) >= 4 : + for y,x in pop_positions : + field[y][x] = "." + return True + return False# 안 터짐 + +answer = 0 +flag = True +k = 0 +while flag : + visited = [] + flag =False + #1. 전체 field에서 뿌요뿌요 탐색 + for i in range(12): + for j in range(6): + if field[i][j]!="." and [i,j] not in visited: + now_f = bfs(i,j) # 2.해당 위치에서 터짐 여부 확인 + flag = flag or now_f + #2. 연쇄 계수 추가 + if not flag : # False - 안터짐 + break + else : + for row in range(6): + refine_field(row) + # 현재 turn 에서 1번 이상 터짐 + answer += 1 +print(answer) \ No newline at end of file From 6a25f66d7f4781885be97187861dbc836cc4f047 Mon Sep 17 00:00:00 2001 From: Hongjoo Date: Sun, 1 Jun 2025 02:29:24 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[BOJ]#7576.=20=ED=86=A0=EB=A7=88=ED=86=A0/?= =?UTF-8?q?=EA=B3=A8=EB=93=9C5/50min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/7576 --- .../\354\236\245\352\265\260.py" | 50 ++++++++++++++++ .../\355\206\240\353\247\210\355\206\240.py" | 60 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 "Hongjoo/\353\260\261\354\244\200/\354\236\245\352\265\260.py" create mode 100644 "Hongjoo/\353\260\261\354\244\200/\355\206\240\353\247\210\355\206\240.py" diff --git "a/Hongjoo/\353\260\261\354\244\200/\354\236\245\352\265\260.py" "b/Hongjoo/\353\260\261\354\244\200/\354\236\245\352\265\260.py" new file mode 100644 index 0000000..2621ab4 --- /dev/null +++ "b/Hongjoo/\353\260\261\354\244\200/\354\236\245\352\265\260.py" @@ -0,0 +1,50 @@ + +import sys +from collections import deque +INF = 1e9 +# 상하좌우 +dy = [-1,1,0,0] +dx = [0,0,-1,1] + +dl= [[-1,1],[1,1],[1,-1],[-1,-1]] # 우상 . 우하 / 좌하 / 좌상 +dl_combined = [0,3,1,2,2,3,0,1] +sy ,sx= map(int,sys.stdin.readline().split()) +ty,tx = map(int, sys.stdin.readline().split()) + +field = [[INF]*9 for _ in range(10)] +field[sy][sx] = 0 +field[ty][tx] = -1 + +q = deque() +q.append([sy,sx]) + +def check_bound(y,x) : + if 0<= y <=9 and 0<= x <=8 and field[y][x]!=-1 : # 기물 x , field 안에 , 방문 상관x => 왕 위치만 안됨x + return True + return False +def check_bound2(y,x) : + if 0<= y <=9 and 0<= x <=8 : # 기물 가능 + return True + return False + +while q : + cy,cx = q.popleft() + for i in range(8): + ny1, nx1 = cy +dy[i//2] , cx+dx[i//2] + ny2, nx2 = ny1 + dl[dl_combined[i]][0] , nx1 + dl[dl_combined[i]][1] + ny3 , nx3 = ny2 + dl[dl_combined[i]][0] , nx2 + dl[dl_combined[i]][1] + + if check_bound(ny1, nx1) and check_bound(ny2, nx2) and check_bound2(ny3, nx3) : + if ny3 == ty and nx3 == tx : + # print(f"succes====") + print(field[cy][cx] +1) + + exit() + elif field[cy][cx] +1 <= field[ny3][nx3] : + field[ny3][nx3] =field[cy][cx] +1 # 업데이트 + # print(f"{cy}{cx} -> {i}: {ny1}{nx1} / {ny2}{nx2} / {ny3}, {nx3} => field{field[ny3][nx3]} ") + + q.append([ny3,nx3]) + # print(f"{cy}{cx} -> {i}: {ny1}{nx2} / {ny2}{nx2} / {ny3}, {nx3} => field{field[ny3][nx3]} ") + +print(field[ty][tx]) \ No newline at end of file diff --git "a/Hongjoo/\353\260\261\354\244\200/\355\206\240\353\247\210\355\206\240.py" "b/Hongjoo/\353\260\261\354\244\200/\355\206\240\353\247\210\355\206\240.py" new file mode 100644 index 0000000..7591309 --- /dev/null +++ "b/Hongjoo/\353\260\261\354\244\200/\355\206\240\353\247\210\355\206\240.py" @@ -0,0 +1,60 @@ +""" +https://www.acmicpc.net/problem/7576 +# BFS, DFS +(1) filed 값 중 1인 값 찾기 +(2) 상하좌우로 -1 빼고 확산 +(3) flag로 해당 이잔 turn에서 확산 유무를 판단 -> 안되면 turn 종료 + +""" +# 입력 +import sys +from collections import deque + +input = sys.stdin.readline +N,M = map(int, input().split()) + +field = [list(map(int,input().split())) for _ in range(M) ] +# print(field) +dy = [-1,1,0,0] +dx = [-0,0,-1,1] +# BFS + + +lv = 0 +burn = [] +q = deque() +for m in range(M) : + for n in range(N) : + # print(m , n) + if field[m][n] == 1: + # 안 익은 토마토 익히기 + q.append([m,n]) + +while q : + # 각 turn 마다 토마도 전염시키기 + + # print(f"{t}턴 - {m}{n}") + #[2] 익은 토마토 확산시키기 + # t+= 1 + y,x = q.popleft() + for d in range(4): + ny = y + dy[d] ; nx = x + dx[d] + if 0<= ny