20250828 baekjoon
This commit is contained in:
parent
8424b1dca2
commit
788d997b7a
22
code_study/Baekjoon/java/_1149.java
Normal file
22
code_study/Baekjoon/java/_1149.java
Normal file
@ -0,0 +1,22 @@
|
||||
import java.util.*;
|
||||
|
||||
public class _1149 {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int N = Integer.parseInt(sc.nextLine());
|
||||
int[] RGB = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
|
||||
int dpR = RGB[0], dpG = RGB[1], dpB = RGB[2];
|
||||
int prevR = dpR, prevG = dpG, prevB = dpB;
|
||||
for(int i=1; i<N; i++) {
|
||||
RGB = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
|
||||
dpR = RGB[0] + Math.min(prevG, prevB);
|
||||
dpG = RGB[1] + Math.min(prevR, prevB);
|
||||
dpB = RGB[2] + Math.min(prevG, prevR);
|
||||
|
||||
prevR = dpR; prevG = dpG; prevB = dpB;
|
||||
}
|
||||
sc.close();
|
||||
|
||||
System.out.println(Math.min(dpR,Math.min(dpG, dpB)));
|
||||
}
|
||||
}
|
||||
17
code_study/Baekjoon/swift/1149.swift
Normal file
17
code_study/Baekjoon/swift/1149.swift
Normal file
@ -0,0 +1,17 @@
|
||||
if let n = readLine(), let N = Int(n) {
|
||||
if let line1 = readLine(), let rgb = line1.split(separator: " ").compactMap({Int($0)}) as? [Int], rgb.count==3 {
|
||||
var dpR = rgb[0], dpG = rgb[1], dpB = rgb[2]
|
||||
var prevR = dpR, prevG = dpG, prevB = dpB
|
||||
|
||||
for _ in 1..<N {
|
||||
if let lineN = readLine(), let RGB = lineN.split(separator: " ").compactMap({Int($0)}) as? [Int], RGB.count==3 {
|
||||
dpR = RGB[0] + min(prevG, prevB)
|
||||
dpG = RGB[1] + min(prevR, prevB)
|
||||
dpB = RGB[2] + min(prevR, prevG)
|
||||
prevR = dpR; prevG = dpG; prevB = dpB
|
||||
}
|
||||
}
|
||||
|
||||
print(min(dpR, dpG, dpB))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user