From f7aefa2cdf8a19e679b5f4aaca3fb1fc5bba8e0e Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Mon, 21 Jul 2025 03:37:10 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[PGS]=20=EC=96=91=EA=B6=81=EB=8C=80?= =?UTF-8?q?=ED=9A=8C=20/=20level=202=20/=20100=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://school.programmers.co.kr/learn/courses/30/lessons/92342 --- ...21\352\266\201\353\214\200\355\232\214.py" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "YoonYn9915/Graph/2025-07-14-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#92342-\354\226\221\352\266\201\353\214\200\355\232\214.py" diff --git "a/YoonYn9915/Graph/2025-07-14-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#92342-\354\226\221\352\266\201\353\214\200\355\232\214.py" "b/YoonYn9915/Graph/2025-07-14-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#92342-\354\226\221\352\266\201\353\214\200\355\232\214.py" new file mode 100644 index 0000000..bb6a457 --- /dev/null +++ "b/YoonYn9915/Graph/2025-07-14-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#92342-\354\226\221\352\266\201\353\214\200\355\232\214.py" @@ -0,0 +1,112 @@ +''' +요구사항 +- k (1~10)점을 어피치가 a발을 맞췄고, 라이언이 b발을 맞혔을 때, b> a이면 k점을 라이언이 가져가고, 아니면 어피치가 k점을 가져간다. 단 a = b = 0일 경우 누구도 k점을 가져가지 못한다. +- 모든 과녁에 대하여 두 선수의 총점 계산, 단 최종 점수가 같으면 어피치를 우승자로 +- 어피치가 n발을 쏜 후 그 정보를 가지고 라이언이 어피치를 가장 큰 점수차로 이기기 위해 n발을 어떻게 맞춰야 하는지 구해라. +- 라이언이 우승할 수 없는 경우 -1을 출력하고, 라이언이 가장 큰 점수차로 이길 수 있는 방법이 여러개인 경우 가장 낮은 점수를 더 많이 맞힌 경우를 반환해야 한다. + + +아이디어 +- 이 문제는 greedy는 아닌거 같다. greedy로 하려면 큰 점수를 무조건 먹기 위해 어피치가 쏜 화살 + 1만큼 할 텐데 입출력 예 1번처럼 라이언이 10점을 먹어도 9점 8점을 어피치가 먹으면 라이언이 지게 된다. +- 따라서 완전 탐색을 진행해야 하며, dfs와 backtracking을 사용하여 깊이 우선으로 모든 경우의 수 계산. +- 양궁대회 시뮬레이션 아이디어: info(어피치의 결과 배열)가 10점부터 0점까지의 나열이므로 10점부터 0점까지 내림차순으로 화살을 쏜다. 모든 경우를 구할 수 없으므로 현재 점수에 대해 라이언이 0발 혹은 info[i] + 1발을 맞춘 경우만 고려하고 나머지 경우는 진행하지 않는다. 즉 어피치가 10점에 2발을 맞췄다면, 라이언은 0발을 맞추고 화살을 아껴 다음 점수로 가던지, 2+1발을 맞춰 화살을 쓰더라도 점수를 얻고 가던지 두가지 경우만 해야 한다. + + +구현 +1. dfs 진행 + - dfs 종료 조건: 현재 점수판이 0점이거나, 남은 화살이 없을때 + - dfs 진행: (점수 그대로, 화살개수 그대로) 혹은 (현재 점수 먹기, 화살개수 소모하기) 두가지 버전으로 나뉨 +2. 라이언과 어피치 중 누가 얼마의 차이로 이겼는지 확인하는 함수 + - 차이가 같다면 가장 낮은 점수를 더 많이 맞춘 배열 선택 + +''' + +# 점수차가 같은 경우 가장 낮은 점수를 많이 쏜 것을 정답으로 +def choose_answer(arr1, arr2): + length = len(arr1) + + # 낮은 점수부터 체크해야 하니까 역순으로 + for i in range(length-1, -1, -1): + if arr1[i] > arr2[i]: + return arr1 + elif arr2[i] > arr1[i]: + return arr2 + + # 반복문이 끝났는데 여기까지 온 경우는 두 배열이 같다는 뜻이므로 아무거나 반환 + return arr1 + + + +# 승자와 점수차를 반환. +def get_winner(lion, appeach): + lion_score = 0 + appeach_score = 0 + length = len(appeach) + for i in range(length): + if lion[i] > 0 or appeach[i] > 0: + # 라이언이 맞춘 화살이 어피치보다 많으면 라이언이 점수를 가져오고 + if lion[i] > appeach[i]: + lion_score += (10 -i) + # 그렇지 않으면 어피치가 점수를 가져온다. + else: + appeach_score += (10 - i) + + # 라이언 승 + if lion_score > appeach_score: + return 1, lion_score - appeach_score + else: + return -1, appeach_score - lion_score + +def dfs(n, idx, lion, appeach): + global max_result, answer + + # dfs 종료 조건. 현재 점수판이 0점이거나, 남은 화살이 없을 때 + if n == 0 or idx == 10: + # 점수판이 0점이면 라이언의 남은 화살 모두 0점에 맞춤 + if idx == 10: + lion[idx] = n + + # 둘 중 누가 승자인지 판단하고, 라이언이 승자면 최대점수인지 확인 + winner, score_gap = get_winner(lion, appeach) + + # 라이언이 승자이면 + if winner == 1: + if max_result < score_gap: + max_result = score_gap + answer = lion + elif max_result == score_gap: + answer = choose_answer(answer, lion) + return + + # 현재 점수를 포기하고 화살을 아껴서 다음 dfs 진행 + dfs(n, idx+1, lion[:], appeach) + + # 어피치보다 한 발 더 쏴서 현재 점수를 먹고 다음 dsf 진행 + if n >= appeach[idx] + 1: + tmp = lion[:] + tmp[idx] = appeach[idx] + 1 + dfs(n - (appeach[idx] + 1), idx+1, tmp, appeach) + + + + +def solution(n, info): + global answer, max_result + # 라이언이 맞춘 점수 초기화 + lion = [0] * 11 + # 정답이 될 배열 + answer = [0] * 11 + + max_result = 0 + + # 10점부터 0점까지 점수판을 내림차순으로 순회하며 몇 발을 맞췄는지 시뮬레이션 하기 위함. + # n은 남은 화살, idx는 현재 점수판(0이면 10점, 10이면 0점) + dfs(n, 0, lion, info) + + if max_result == 0: + print([-1]) + else: + print(answer) + + +solution(10, [0,0,0,0,0,0,0,0,3,4,3]) From 77269f4c7abc127e443306f9764d9d80d6317649 Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 2 Aug 2025 23:46:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[PGS]=20=EA=B1=B0=EB=A6=AC=EB=91=90?= =?UTF-8?q?=EA=B8=B0=20/=20level=202=20/=2070=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://school.programmers.co.kr/learn/courses/30/lessons/81302 --- ...60\353\246\254\353\221\220\352\270\260.py" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "YoonYn9915/Graph/2025-07-28-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#81302-\352\261\260\353\246\254\353\221\220\352\270\260.py" diff --git "a/YoonYn9915/Graph/2025-07-28-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#81302-\352\261\260\353\246\254\353\221\220\352\270\260.py" "b/YoonYn9915/Graph/2025-07-28-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#81302-\352\261\260\353\246\254\353\221\220\352\270\260.py" new file mode 100644 index 0000000..52bd6a4 --- /dev/null +++ "b/YoonYn9915/Graph/2025-07-28-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-#81302-\352\261\260\353\246\254\353\221\220\352\270\260.py" @@ -0,0 +1,51 @@ + +from collections import deque + +def bfs(places, i, j, k): + queue = deque() + queue.append((j, k, 0)) # row, col, dist + visited = [[False] * 5 for _ in range(5)] + visited[j][k] = True + + dx = [-1, 1, 0, 0] + dy = [0, 0, -1, 1] + + while queue: + row, col, dist = queue.popleft() + + if dist != 0 and places[i][row][col] == 'P': + return 1 + + if dist == 2: + continue + + for d in range(4): + nr = row + dx[d] + nc = col + dy[d] + + if 0 <= nr < 5 and 0 <= nc < 5 and not visited[nr][nc]: + if places[i][nr][nc] != 'X': + visited[nr][nc] = True + queue.append((nr, nc, dist + 1)) + + return 0 + + +def solution(places): + answer = [] + + for i in range(5): # 5 rooms + violated = False + for j in range(5): + for k in range(5): + if places[i][j][k] == 'P': + if bfs(places, i, j, k): + violated = True + break + if violated: + break + answer.append(0 if violated else 1) + + return answer + + From a30b613c59a0ae1d13c91afa4a94de8a247e78cf Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 2 Aug 2025 23:50:49 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[=EB=B0=B1=EC=A4=80]=20=EC=95=88=EC=A0=84?= =?UTF-8?q?=EC=98=81=EC=97=AD=20/=20=EC=8B=A4=EB=B2=84=201=20/=2050?= =?UTF-8?q?=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/2468 --- ...10\354\240\204\354\230\201\354\227\255.py" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "YoonYn9915/Graph/2025-08-02-[\353\260\261\354\244\200]-#2468-\354\225\210\354\240\204\354\230\201\354\227\255.py" diff --git "a/YoonYn9915/Graph/2025-08-02-[\353\260\261\354\244\200]-#2468-\354\225\210\354\240\204\354\230\201\354\227\255.py" "b/YoonYn9915/Graph/2025-08-02-[\353\260\261\354\244\200]-#2468-\354\225\210\354\240\204\354\230\201\354\227\255.py" new file mode 100644 index 0000000..400fede --- /dev/null +++ "b/YoonYn9915/Graph/2025-08-02-[\353\260\261\354\244\200]-#2468-\354\225\210\354\240\204\354\230\201\354\227\255.py" @@ -0,0 +1,52 @@ +import sys + +input = sys.stdin.readline +from collections import deque + +N = int(input()) +graph = [list(map(int, input().split())) for _ in range(N)] +high = 0 + +for i in range(N): + for j in range(N): + if graph[i][j] > high: + high = graph[i][j] + +dx, dy = [0, 0, -1, 1], [-1, 1, 0, 0] +queue = deque() + + +def bfs(i, j, high): + queue.append((i, j)) + visited[i][j] = 1 + + while queue: + x, y = queue.popleft() + + for i in range(4): + nx = dx[i] + x + ny = dy[i] + y + + if nx < 0 or nx >= N or ny < 0 or ny >= N: + continue + + if graph[nx][ny] > high and visited[nx][ny] == 0: + visited[nx][ny] = 1 + queue.append((nx, ny)) + + +result = 0 +for k in range(high): + visited = [[0] * N for _ in range(N)] + ans = 0 + + for i in range(N): + for j in range(N): + if graph[i][j] > k and visited[i][j] == 0: + bfs(i, j, k) + ans += 1 + + if result < ans: + result = ans + +print(result) From 817305b9613ba7eca305327dd87a7b922bf3af52 Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 2 Aug 2025 23:54:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[=EB=B0=B1=EC=A4=80]=20=EB=B3=B4=EB=AC=BC?= =?UTF-8?q?=20/=20=EC=8B=A4=EB=B2=84=204=20/=2030=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/1026 --- ...61\354\244\200]-#1026-\353\263\264\353\254\274.py" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "YoonYn9915/greedy/2025-08-02-[\353\260\261\354\244\200]-#1026-\353\263\264\353\254\274.py" diff --git "a/YoonYn9915/greedy/2025-08-02-[\353\260\261\354\244\200]-#1026-\353\263\264\353\254\274.py" "b/YoonYn9915/greedy/2025-08-02-[\353\260\261\354\244\200]-#1026-\353\263\264\353\254\274.py" new file mode 100644 index 0000000..562f0b8 --- /dev/null +++ "b/YoonYn9915/greedy/2025-08-02-[\353\260\261\354\244\200]-#1026-\353\263\264\353\254\274.py" @@ -0,0 +1,11 @@ +n = int(input()) +a = list(map(int, input().split())) +b = list(map(int, input().split())) +a.sort() +s = 0 +for i in range(n): + b_max = max(b) + s += a[i] * b_max + b.remove(b_max) + +print(s) \ No newline at end of file