-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1149.java
More file actions
52 lines (41 loc) ยท 1.29 KB
/
_1149.java
File metadata and controls
52 lines (41 loc) ยท 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package backjoon;
// https://www.acmicpc.net/problem/1149
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _1149 {
final static int Red = 0;
final static int Green = 1;
final static int Blue = 2;
static int[][] Cost;
public static void main(String[] args) throws IOException {
// memory 12036 runtime 92
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
Cost = new int[N][3];
StringTokenizer st;
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
Cost[i][Red] = Integer.parseInt(st.nextToken());
Cost[i][Green] = Integer.parseInt(st.nextToken());
Cost[i][Blue] = Integer.parseInt(st.nextToken());
}
// ๋ชจ๋ ๊ฒฝ์ฐ์ ์ ์ค ์ต์๊ฐ์ ๋ํ๊ธฐ
for (int i = 1; i < N; i++) {
Cost[i][Red] += Math.min(Cost[i - 1][Green], Cost[i - 1][Blue]);
Cost[i][Green] += Math.min(Cost[i - 1][Red], Cost[i - 1][Blue]);
Cost[i][Blue] += Math.min(Cost[i - 1][Red], Cost[i - 1][Green]);
}
System.out.println(Math.min(Math.min(Cost[N - 1][Red], Cost[N - 1][Green]), Cost[N - 1][Blue]));
}
}
/*
input
3
26 40 83
49 60 57
13 89 99
output
96
*/