From a764f66d71557999894ac4858103f4989a692ee7 Mon Sep 17 00:00:00 2001 From: jhg3410 Date: Mon, 20 May 2024 19:47:22 +0900 Subject: [PATCH] solve: 63week --- ...4\355\230\270 \354\240\234\352\261\260.py" | 32 +++++++++++++++ ...4\354\213\234 \352\261\264\354\204\244.py" | 41 +++++++++++++++++++ ... \352\260\204 \354\244\200\355\225\230.py" | 41 +++++++++++++++++++ ...4 \354\261\204\354\232\260\352\270\260.py" | 16 ++++++++ 4 files changed, 130 insertions(+) create mode 100644 "src/main/kotlin/heejik/63week/\352\264\204\355\230\270 \354\240\234\352\261\260.py" create mode 100644 "src/main/kotlin/heejik/63week/\353\217\204\354\213\234 \352\261\264\354\204\244.py" create mode 100644 "src/main/kotlin/heejik/63week/\354\213\270\354\247\200\353\260\251\354\227\220 \352\260\204 \354\244\200\355\225\230.py" create mode 100644 "src/main/kotlin/heejik/63week/\355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260.py" diff --git "a/src/main/kotlin/heejik/63week/\352\264\204\355\230\270 \354\240\234\352\261\260.py" "b/src/main/kotlin/heejik/63week/\352\264\204\355\230\270 \354\240\234\352\261\260.py" new file mode 100644 index 00000000..3df7f1fd --- /dev/null +++ "b/src/main/kotlin/heejik/63week/\352\264\204\355\230\270 \354\240\234\352\261\260.py" @@ -0,0 +1,32 @@ +exp = input() +answers = [] + + +def dfs(start_idx, now_exp): + if now_exp not in answers: + answers.append(now_exp) + # start_idx 포함 이후부터 ( 이게 없으면 그냥 리턴하는 것도 고려 + for i in range(start_idx, len(now_exp)): + if now_exp[i] == '(': + # 여기에 맞는 닫는 괄호를 찾아야 한다 + close_idx = find_idx(i, now_exp) + dfs(start_idx=i, now_exp=now_exp[:i] + now_exp[i + 1:close_idx] + now_exp[close_idx + 1:]) + + +def find_idx(i, find_exp): + cnt = 1 + for idx, char in enumerate(find_exp[i + 1:]): + if char == ')': + cnt -= 1 + if cnt == 0: + return i + 1 + idx + if char == '(': + cnt += 1 + + +if __name__ == '__main__': + dfs(start_idx=0, now_exp=exp) + answers.sort() + answers.remove(exp) + for answer in answers: + print(answer) diff --git "a/src/main/kotlin/heejik/63week/\353\217\204\354\213\234 \352\261\264\354\204\244.py" "b/src/main/kotlin/heejik/63week/\353\217\204\354\213\234 \352\261\264\354\204\244.py" new file mode 100644 index 00000000..7a450c46 --- /dev/null +++ "b/src/main/kotlin/heejik/63week/\353\217\204\354\213\234 \352\261\264\354\204\244.py" @@ -0,0 +1,41 @@ +n, m = map(int, input().split()) +all_cost = 0 +minimum_cost = 0 +edges = [] +parents = [i for i in range(n + 1)] + +for _ in range(m): + a, b, cost = map(int, input().split()) + all_cost += cost + edges.append([a, b, cost]) + +edges.sort(key=lambda x: x[2]) + +for a, b, cost in edges: + parentA = a + parentB = b + + while parentA != parents[parentA]: + parentA = parents[parentA] + + while parentB != parents[parentB]: + parentB = parents[parentB] + + if parentA == parentB: + continue + + if parentA < parentB: + parents[parentB] = parentA + else: + parents[parentA] = parentB + + minimum_cost += cost + +count = 0 +for i in range(1, n + 1): + if i == parents[i]: + count += 1 +if count > 1: + print(-1) +else: + print(all_cost - minimum_cost) diff --git "a/src/main/kotlin/heejik/63week/\354\213\270\354\247\200\353\260\251\354\227\220 \352\260\204 \354\244\200\355\225\230.py" "b/src/main/kotlin/heejik/63week/\354\213\270\354\247\200\353\260\251\354\227\220 \352\260\204 \354\244\200\355\225\230.py" new file mode 100644 index 00000000..2ab1685f --- /dev/null +++ "b/src/main/kotlin/heejik/63week/\354\213\270\354\247\200\353\260\251\354\227\220 \352\260\204 \354\244\200\355\225\230.py" @@ -0,0 +1,41 @@ +import heapq +import sys + +input = sys.stdin.readline + + +def solve(): + while people: + start, end = heapq.heappop(people) + + # 시간이 다 된 자리는 뺀다. + while seat and seat[0][0] <= start: + end_time, idx = heapq.heappop(seat) + heapq.heappush(possible_index, idx) + + # 사람을 자리에 넣는 부분 + if possible_index: + idx = heapq.heappop(possible_index) + else: + idx = len(seat) + + heapq.heappush(seat, [end, idx]) + answer[idx] += 1 + + count_seat = answer.index(0) + print(count_seat) + print(*answer[:count_seat]) + + +if __name__ == '__main__': + n = int(input()) + people = [] + seat = [] + possible_index = [] + answer = [0 for _ in range(n + 1)] + + for _ in range(n): + start, end = map(int, input().split()) + heapq.heappush(people, [start, end]) + + solve() diff --git "a/src/main/kotlin/heejik/63week/\355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260.py" "b/src/main/kotlin/heejik/63week/\355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260.py" new file mode 100644 index 00000000..8040ad10 --- /dev/null +++ "b/src/main/kotlin/heejik/63week/\355\203\200\354\235\274 \354\261\204\354\232\260\352\270\260.py" @@ -0,0 +1,16 @@ +if __name__ == '__main__': + n = int(input()) + dp = [0 for _ in range(n + 1)] + if n % 2 == 1: + print(dp[n]) + exit(0) + + dp[2] = 3 + + for x in range(4, n + 1, 2): + dp[x] += (dp[x - 2] * dp[2]) + for i in range(2, x - 2, 2): + dp[x] += 2 * dp[i] + dp[x] += 2 + + print(dp[n])