baekjoon 20260126

This commit is contained in:
songyc macbook 2026-01-26 20:50:13 +09:00
parent 32dd42ca61
commit 169fcca00e
2 changed files with 83 additions and 0 deletions

View 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;
}

View 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()