From 73b3aca3fbff77cc14f52272d0bc148e5f18b01e Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 26 Apr 2025 23:23:35 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[BOJ]=20=EB=91=90=20=EC=9A=A9=EC=95=A1=20/?= =?UTF-8?q?=20=EA=B3=A8=EB=93=9C=205=20/=2040=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/2470 --- ...-\353\221\220 \354\232\251\354\225\241.py" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "YoonYn9915/binary search/2025-04-18-[\353\260\261\354\244\200]-#2470-\353\221\220 \354\232\251\354\225\241.py" diff --git "a/YoonYn9915/binary search/2025-04-18-[\353\260\261\354\244\200]-#2470-\353\221\220 \354\232\251\354\225\241.py" "b/YoonYn9915/binary search/2025-04-18-[\353\260\261\354\244\200]-#2470-\353\221\220 \354\232\251\354\225\241.py" new file mode 100644 index 0000000..7b3c625 --- /dev/null +++ "b/YoonYn9915/binary search/2025-04-18-[\353\260\261\354\244\200]-#2470-\353\221\220 \354\232\251\354\225\241.py" @@ -0,0 +1,27 @@ +import sys + +N = int(sys.stdin.readline()) +arr = sorted(map(int, sys.stdin.readline().split())) + +left = 0 +right = N - 1 + +answer = (arr[left], arr[right], abs(arr[left] + arr[right])) + +# 투 포인터 사용해서 절대값이 0에 가장 가까운 두 값 찾기 +while left < right: + total = arr[left] + arr[right] + abs_total = abs(total) + + if abs_total < answer[2]: + answer = (arr[left], arr[right], abs_total) + if abs_total == 0: + break + # 두 용액의 값이 0보다 크면 right를 줄여서 합을 작게 만든다 + if total > 0: + right -= 1 + else: + # 두 용액의 값이 0보다 작으면 left를 늘려서 합을 크게 만든다 + left += 1 + +print(f"{answer[0]} {answer[1]}") \ No newline at end of file From b372219622220694028d84956ea3716e686d2856 Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 26 Apr 2025 23:23:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[BOJ]=20=EC=84=B8=20=EC=9A=A9=EC=95=A1=20/?= =?UTF-8?q?=20=EA=B3=A8=EB=93=9C=203=20/=2080=EB=B6=84=20=ED=9E=8C?= =?UTF-8?q?=ED=8A=B8=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/2473 --- ...-\354\204\270 \354\232\251\354\225\241.py" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "YoonYn9915/binary search/2025-04-26-[\353\260\261\354\244\200]-#2473-\354\204\270 \354\232\251\354\225\241.py" diff --git "a/YoonYn9915/binary search/2025-04-26-[\353\260\261\354\244\200]-#2473-\354\204\270 \354\232\251\354\225\241.py" "b/YoonYn9915/binary search/2025-04-26-[\353\260\261\354\244\200]-#2473-\354\204\270 \354\232\251\354\225\241.py" new file mode 100644 index 0000000..8524d64 --- /dev/null +++ "b/YoonYn9915/binary search/2025-04-26-[\353\260\261\354\244\200]-#2473-\354\204\270 \354\232\251\354\225\241.py" @@ -0,0 +1,43 @@ +import sys + +inp = sys.stdin.readline + +N = int(inp()) +arr = list(map(int, inp().split())) +arr.sort() + +min_value = int(1e10) +answer = [-1, -1, -1] + +# 각 용액을 순회하며 +for i in range(N): + left = i + 1 + right = N - 1 + + # i번 용액을 넣었을 때 값이 가장 0에 가까운 두 값 찾기 + while left < right: + if left == i: + left = i + 1 + continue + elif right == i: + right = i - 1 + continue + + total = arr[i] + arr[left] + arr[right] + + # 세 용액의 합이 0에 가장 가까우면 업데이트 + if abs(total) < min_value: + min_value = abs(total) + answer = [arr[i], arr[left], arr[right]] + + if total == 0: + break + elif total < 0: + left += 1 + else: + right -= 1 + +answer.sort() + +for ans in answer: + print(ans, end=" ") From c99671da25c7203fec5a3778ee8361df7a84ad46 Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sat, 26 Apr 2025 23:23:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[BOJ]=20=EC=9E=90=EB=91=90=20=EB=82=98?= =?UTF-8?q?=EB=AC=B4=20/=20=EA=B3=A8=EB=93=9C=205=20/=2080=EB=B6=84=20?= =?UTF-8?q?=ED=9E=8C=ED=8A=B8=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/2240 --- ...0\353\221\220 \353\202\230\353\254\264.py" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "YoonYn9915/dp/2025-04-26-[\353\260\261\354\244\200]-#2240-\354\236\220\353\221\220 \353\202\230\353\254\264.py" diff --git "a/YoonYn9915/dp/2025-04-26-[\353\260\261\354\244\200]-#2240-\354\236\220\353\221\220 \353\202\230\353\254\264.py" "b/YoonYn9915/dp/2025-04-26-[\353\260\261\354\244\200]-#2240-\354\236\220\353\221\220 \353\202\230\353\254\264.py" new file mode 100644 index 0000000..909be12 --- /dev/null +++ "b/YoonYn9915/dp/2025-04-26-[\353\260\261\354\244\200]-#2240-\354\236\220\353\221\220 \353\202\230\353\254\264.py" @@ -0,0 +1,34 @@ +from sys import stdin + +T, W = map(int, stdin.readline().split()) + + +lst = [0] +dp = [[0]*(W+1) for _ in range(T+1)] + +# 입력 받기 +for _ in range(T): + lst.append(int(stdin.readline())) + +# DP 테이블 채우기 +for i in range(1, T+1): + if lst[i] == 1: + # 이동을 한 번도 안 했을 경우 (항상 1번 나무 아래 있음) + dp[i][0] = dp[i-1][0] + 1 # 자두 먹으면 +1 + else: + # 1번 나무 아래 있는데 2번 나무에서 자두 떨어지면 못 먹음 + dp[i][0] = dp[i-1][0] + + # 이동 횟수 1회 이상부터 + for j in range(1, W+1): + if lst[i] == 2 and j % 2 == 1: + # 홀수번 이동했을 때는 2번 나무 아래 있음 → 2번 나무에서 자두 떨어지면 +1 + dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + 1 + elif lst[i] == 1 and j % 2 == 0: + # 짝수번 이동했을 때는 1번 나무 아래 있음 → 1번 나무에서 자두 떨어지면 +1 + dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + 1 + else: + # 자두 못 먹을 경우, 이동하거나 이동 안 하거나 둘 중 최대값만 가져오기 + dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + +print(max(dp[-1]))