baekjoon 20260120
This commit is contained in:
parent
929b070cd1
commit
1852d5b1af
8
code_study/Baekjoon/python/13118.py
Normal file
8
code_study/Baekjoon/python/13118.py
Normal file
@ -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)
|
||||
44
code_study/Baekjoon/ts/1516.ts
Normal file
44
code_study/Baekjoon/ts/1516.ts
Normal file
@ -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"));
|
||||
Loading…
x
Reference in New Issue
Block a user