baekjoon 20260126
This commit is contained in:
parent
32dd42ca61
commit
169fcca00e
17
code_study/Baekjoon/c/11945.c
Normal file
17
code_study/Baekjoon/c/11945.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N, M;
|
||||||
|
scanf("%d %d", &N, &M);
|
||||||
|
|
||||||
|
char* line = (char*)malloc(sizeof(char)*(M+1));
|
||||||
|
while(N--) {
|
||||||
|
scanf("%s",line);
|
||||||
|
for(int i=M-1; i>=0; i--) printf("%c",line[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(line);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
66
code_study/Baekjoon/swift/1005_1.swift
Normal file
66
code_study/Baekjoon/swift/1005_1.swift
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
func main() {
|
||||||
|
var ans: [Int] = []
|
||||||
|
|
||||||
|
guard let T = Int(readLine() ?? "") else { return }
|
||||||
|
|
||||||
|
for _ in 0..<T {
|
||||||
|
guard let input1 = readLine() else { return }
|
||||||
|
|
||||||
|
let NK = input1.split(separator: " ").compactMap{Int($0)}
|
||||||
|
let (N, K) = (NK[0], NK[1])
|
||||||
|
|
||||||
|
guard let input2 = readLine() else { return }
|
||||||
|
let build_time: [Int] = [0] + input2.split(separator: " ").compactMap{Int($0)}
|
||||||
|
|
||||||
|
var graph: [[Int]] = Array(repeating: [], count: N+1)
|
||||||
|
var indegree: [Int] = Array(repeating: 0, count: N+1)
|
||||||
|
|
||||||
|
for _ in 0..<K {
|
||||||
|
guard let input3 = readLine(),
|
||||||
|
let XY = input3.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
||||||
|
let X = XY.first, let Y = XY.last
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
indegree[Y] += 1
|
||||||
|
graph[X].append(Y)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let W: Int = Int(readLine() ?? "") else { return }
|
||||||
|
|
||||||
|
var dp: [Int] = Array(repeating: 0, count: N+1)
|
||||||
|
var qu: [Int] = Array(repeating: 0, count: N+1)
|
||||||
|
var (front, rear) = (0, 0)
|
||||||
|
|
||||||
|
for n in 1...N {
|
||||||
|
if indegree[n] == 0 {
|
||||||
|
qu[rear] = n
|
||||||
|
rear += 1
|
||||||
|
dp[n] = build_time[n]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while front < rear {
|
||||||
|
let now = qu[front]
|
||||||
|
front += 1
|
||||||
|
|
||||||
|
if now == W {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
for nxt in graph[now] {
|
||||||
|
indegree[nxt] -= 1
|
||||||
|
dp[nxt] = max(dp[nxt], dp[now] + build_time[nxt])
|
||||||
|
if indegree[nxt] == 0 {
|
||||||
|
qu[rear] = nxt
|
||||||
|
rear += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ans.append(dp[W])
|
||||||
|
}
|
||||||
|
|
||||||
|
print(ans.map({String($0)}).joined(separator: "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user