From 1852d5b1af7024fa227e7996bac08b90b4dae89b Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Tue, 20 Jan 2026 21:24:35 +0900 Subject: [PATCH] baekjoon 20260120 --- code_study/Baekjoon/python/13118.py | 8 ++++++ code_study/Baekjoon/ts/1516.ts | 44 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 code_study/Baekjoon/python/13118.py create mode 100644 code_study/Baekjoon/ts/1516.ts diff --git a/code_study/Baekjoon/python/13118.py b/code_study/Baekjoon/python/13118.py new file mode 100644 index 0000000..55d1a42 --- /dev/null +++ b/code_study/Baekjoon/python/13118.py @@ -0,0 +1,8 @@ +mans = list(map(int, input().split())) +apple = list(map(int, input().split()))[0] +ans = 0 +for i in range(len(mans)) : + if apple == mans[i] : + ans = i+1 + break +print(ans) \ No newline at end of file diff --git a/code_study/Baekjoon/ts/1516.ts b/code_study/Baekjoon/ts/1516.ts new file mode 100644 index 0000000..4d85302 --- /dev/null +++ b/code_study/Baekjoon/ts/1516.ts @@ -0,0 +1,44 @@ +export {}; +const input = require("fs").readFileSync(0).toString().trim().split("\n"); +const N: number = Number(input[0]); + +let graph: number[][] = Array.from({length: N+1}, () => []); +let build_time: number[] = new Array(N+1).fill(0); +let indegree: number[] = new Array(N+1).fill(0); +let complete_time: number[] = new Array(N+1).fill(-1); + +for(let i=1; i<=N; i++) { + const line: number[] = input[i].split(" ").map(Number); + build_time[i] = line[0]; + + for(let prev of line.slice(1)) { + if(prev === -1) break; + + indegree[i]++; + graph[prev].push(i); + } +} + +let qu: number[] = new Array(N+1).fill(0); +let [front, rear]: number[] = [0,0]; + +for(let i=1; i<=N; i++) { + if(indegree[i] === 0) { + qu[rear++] = i; + complete_time[i] = build_time[i]; + } +} + +while(front < rear) { + const now: number = qu[front++]; + + for(let next of graph[now]) { + indegree[next]--; + complete_time[next] = Math.max(complete_time[next], complete_time[now] + build_time[next]); + if(indegree[next] === 0) { + qu[rear++] = next; + } + } +} + +console.log(complete_time.slice(1).join("\n")); \ No newline at end of file