Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9918da3

Browse files
committed
고다혜: [BOJ] 2096 내려가기_241113
1 parent d729f7b commit 9918da3

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎BOJ/1000-5000번/DH_2096.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/*
5+
* 내려가기
6+
*/
7+
8+
public class DH_2096 {
9+
static int[][] map, max, min;
10+
11+
public static void main(String[] args) throws Exception {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st;
14+
15+
int N = Integer.parseInt(br.readLine());
16+
map = new int[N + 1][3];
17+
max = new int[N + 1][3]; // 각 줄마다 최댓값을 저장할 변수
18+
min = new int[N + 1][3]; // 각 줄마다 최솟값을 저장할 변수
19+
20+
// 최솟값을 저장하는 변수는 무한으로 초기화
21+
for(int r = 1; r < min.length; r++) Arrays.fill(min[r], Integer.MAX_VALUE >> 2);
22+
for(int r = 1; r < map.length; r++) {
23+
st= new StringTokenizer(br.readLine());
24+
for(int c = 0; c < 3; c++) map[r][c] = Integer.parseInt(st.nextToken());
25+
26+
for(int pc = 0; pc < 3; pc++) {
27+
for(int dc = -1; dc < 2; dc++) {
28+
int nc = pc + dc;
29+
if(nc < 0 || nc >= 3) continue;
30+
31+
max[r][nc] = Math.max(max[r - 1][pc] + map[r][nc], max[r][nc]);
32+
min[r][nc] = Math.min(min[r - 1][pc] + map[r][nc], min[r][nc]);
33+
}
34+
}
35+
}
36+
37+
int maxValue = Integer.MIN_VALUE, minValue = Integer.MAX_VALUE;
38+
for(int c = 0; c < 3; c++) {
39+
maxValue = Math.max(maxValue, max[N][c]);
40+
minValue = Math.min(minValue, min[N][c]);
41+
}
42+
43+
System.out.println(maxValue + " " + minValue);
44+
}
45+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /