Skip to content

Commit

Permalink
2024-05-26
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed May 25, 2024
1 parent 93acc1f commit ee60609
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@
| 53์ฐจ์‹œ | 2024.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 54์ฐจ์‹œ | 2024.05.14 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/9370">๋ฏธํ™•์ธ ๋„์ฐฉ์ง€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185
| 55์ฐจ์‹œ | 2023.05.18 | ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ | <a href="https://www.acmicpc.net/problem/4195">์นœ๊ตฌ ๋„คํŠธ์›Œํฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189
| 57์ฐจ์‹œ | 2023.05.26 | ๋ถ„ํ•  ์ •๋ณต | <a href="https://www.acmicpc.net/problem/2263">ํŠธ๋ฆฌ์˜ ์ˆœํšŒ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/197
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()

N = int(input())
in_order = list(map(int,input().split()))
post_order = list(map(int,input().split()))
position = [0 for _ in range(N+1)]

for idx, element in enumerate(in_order):
position[element] = idx

def divide_and_conquer(in_start, in_end, post_start, post_end):
if in_start > in_end or post_start > post_end: return

in_order_root = post_order[post_end]
print(in_order_root, end=" ")

root_idx = position[in_order_root]

divide_and_conquer(in_start, root_idx-1, post_start, post_start+(root_idx - in_start) -1)
divide_and_conquer(root_idx+1, in_end, post_start+(root_idx - in_start), post_end-1)

return

divide_and_conquer(0, N-1, 0, N-1)

0 comments on commit ee60609

Please sign in to comment.