From 57319cb11506090c12833503087a2d4d1abd39fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=A1=E1=84=8C=E1=85=B5=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 5 Sep 2022 20:48:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Solve:=20=EB=91=90=20=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=EC=9D=98=20=ED=95=A9=20[#115]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boj/class5/2143.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 boj/class5/2143.py diff --git a/boj/class5/2143.py b/boj/class5/2143.py new file mode 100644 index 0000000..550a58d --- /dev/null +++ b/boj/class5/2143.py @@ -0,0 +1,23 @@ +# Ex_2143 두 배열의 합 [골3] +from collections import defaultdict + +T = int(input()) + +n = int(input()) +aList = list(map(int, input().split())) +aSum = defaultdict(int) + +m = int(input()) +bList = list(map(int, input().split())) + +answer = 0 + +for i in range(n): + for j in range(i, n): + aSum[sum(aList[i:j + 1])] += 1 + +for i in range(m): + for j in range(i, m): + answer += aSum[T - sum(bList[i: j + 1])] + +print(answer) From 2dfba8c3c8d595b8c2e26efbd7436cc518d0073f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=A1=E1=84=8C=E1=85=B5=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Mon, 5 Sep 2022 21:25:40 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Solve:=20=EC=86=8C=EC=88=98=EC=9D=98=20?= =?UTF-8?q?=EC=97=B0=EC=86=8D=ED=95=A9=20[#115]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boj/class5/1644.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 boj/class5/1644.py diff --git a/boj/class5/1644.py b/boj/class5/1644.py new file mode 100644 index 0000000..8954630 --- /dev/null +++ b/boj/class5/1644.py @@ -0,0 +1,41 @@ +# Ex_1644 소수의 연속합 [골3] +import math +from collections import defaultdict + +N = int(input()) + +primes = [] +isPrime = [True] * (N + 1) +sumDict = defaultdict(int) +answer = 0 + +# set prime bool +for i in range(2, int(math.sqrt(N)) + 1): + if isPrime[i]: + j = 2 + while i * j <= N: + isPrime[i * j] = False + j += 1 + +# set prime num +for i in range(2, N + 1): + if isPrime[i]: + primes.append(i) + +# prefix sum +for i in range(len(primes)): + sumPrime = primes[i] + + if sumPrime == N: + answer += 1 + + for j in range(i + 1, len(primes)): + sumPrime += primes[j] + + if sumPrime > N: + break + + if sumPrime == N: + answer += 1 + +print(answer) From 1a6d9c2d9ad8757bd3846961ae876b127ee8c3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=A1=E1=84=8C=E1=85=B5=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Fri, 9 Sep 2022 17:32:43 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Solve:=20=EB=B6=80=EB=B6=84=EC=88=98?= =?UTF-8?q?=EC=97=B4=EC=9D=98=ED=95=A9=202=20[#115]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boj/class5/1208.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 boj/class5/1208.py diff --git a/boj/class5/1208.py b/boj/class5/1208.py new file mode 100644 index 0000000..824d7a2 --- /dev/null +++ b/boj/class5/1208.py @@ -0,0 +1,46 @@ +# Ex_1208 부분수열의 합 2 [골1] + +def getSubset(length, start): + target = [0] * (1 << length) + for i in range(1 << length): + for j in range(length): + if (i & (1 << j)) > 0: + target[i] += nList[start + j] + + return target + + +N, S = map(int, input().split()) +nList = list(map(int, input().split())) +answer = 0 + +a = N // 2 +b = N - a + +left = sorted(getSubset(a, 0)) +right = sorted(getSubset(b, a), reverse=True) + +i, j = 0, 0 +while i < (1 << a) and j < (1 << b): + + if left[i] + right[j] == S: + left_stack, right_stack = 1, 1 + + while i < ((1 << a) - 1) and left[i] == left[i + 1]: + left_stack += 1 + i += 1 + + while j < ((1 << b) - 1) and right[j] == right[j + 1]: + right_stack += 1 + j += 1 + + answer += left_stack * right_stack + i, j = i + 1, j + 1 + + elif left[i] + right[j] < S: + i += 1 + + else: + j += 1 + +print(answer if S != 0 else answer - 1) From 96c8700703b6603d2eb963e4d4bfee2778192b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8E=E1=85=A1=E1=84=8C=E1=85=B5=E1=84=8B=E1=85=AF?= =?UTF-8?q?=E1=86=AB?= Date: Sat, 10 Sep 2022 15:41:37 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Solve:=20=EC=B9=B4=EB=93=9C=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20[#115]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boj/class5/16566.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 boj/class5/16566.py diff --git a/boj/class5/16566.py b/boj/class5/16566.py new file mode 100644 index 0000000..caa662d --- /dev/null +++ b/boj/class5/16566.py @@ -0,0 +1,35 @@ +# Ex_16566 카드게임 [플5] +# upper bound +def upperBound(target): + s, e = 0, M + + while s < e: + mid = (s + e) // 2 + if cards[mid] <= target: + s = mid + 1 + else: + e = mid + return e + + +def find(x): + if graph[x] != x: + graph[x] = find(graph[x]) + return graph[x] + + +def union(child, parent): + if parent < M: + graph[find(child)] = find(parent) + + +N, M, K = map(int, input().split()) +cards = sorted(map(int, input().split())) +cCards = list(map(int, input().split())) +graph = list(i for i in range(M)) + +for cCard in cCards: + index = find(upperBound(cCard)) + print(cards[index]) + + union(index, index + 1)