baekjoon 20260423
This commit is contained in:
parent
49eb88462d
commit
9535c6bd47
35
code_study/Baekjoon/c/2263.c
Normal file
35
code_study/Baekjoon/c/2263.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int N, res_idx = 0;
|
||||||
|
int inOrderIdx[100001];
|
||||||
|
int inOrder[100000];
|
||||||
|
int postOrder[100000];
|
||||||
|
int preOrder[100000];
|
||||||
|
|
||||||
|
void find(int in_start, int in_end, int post_start, int post_end) {
|
||||||
|
if(in_start > in_end || post_start > post_end) return;
|
||||||
|
|
||||||
|
int root = postOrder[post_end];
|
||||||
|
int root_idx = inOrderIdx[root];
|
||||||
|
int left_size = root_idx - in_start;
|
||||||
|
|
||||||
|
preOrder[res_idx++] = root;
|
||||||
|
find(in_start, root_idx - 1, post_start, post_start + left_size - 1);
|
||||||
|
find(root_idx + 1, in_end, post_start + left_size, post_end - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%d",&N);
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) {
|
||||||
|
scanf("%d",&inOrder[i]);
|
||||||
|
inOrderIdx[inOrder[i]] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) scanf("%d",&postOrder[i]);
|
||||||
|
find(0, N-1, 0, N-1);
|
||||||
|
|
||||||
|
for(int i=0; i<N; i++) printf("%d ",preOrder[i]);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
1
code_study/Baekjoon/python/15740.py
Normal file
1
code_study/Baekjoon/python/15740.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(sum(map(int, input().split())))
|
||||||
Loading…
x
Reference in New Issue
Block a user