Skip to content

Commit e6783d3

Browse files
authored
Merge pull request #1976 from AlgorithmWithGod/JHLEE325
[20260227] BOJ / G5 / 주사위 쌓기 / 이준희
2 parents 5ab2faa + aa64b5d commit e6783d3

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static int N;
7+
static int[][] dice;
8+
static int[] pair = {5, 3, 4, 1, 2, 0};
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
N = Integer.parseInt(br.readLine());
13+
dice = new int[N][6];
14+
15+
for (int i = 0; i < N; i++) {
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
for (int j = 0; j < 6; j++) {
18+
dice[i][j] = Integer.parseInt(st.nextToken());
19+
}
20+
}
21+
22+
int maxTotal = 0;
23+
24+
for (int i = 1; i <= 6; i++) {
25+
maxTotal = Math.max(maxTotal, solve(i));
26+
}
27+
28+
System.out.println(maxTotal);
29+
}
30+
31+
static int solve(int firstnum) {
32+
int sideSum = 0;
33+
int curBottom = firstnum;
34+
35+
for (int i = 0; i < N; i++) {
36+
int bottomIdx = 0;
37+
for (int j = 0; j < 6; j++) {
38+
if (dice[i][j] == curBottom) {
39+
bottomIdx = j;
40+
break;
41+
}
42+
}
43+
44+
int topIdx = pair[bottomIdx];
45+
int topNum = dice[i][topIdx];
46+
47+
int sideMax = 0;
48+
for (int j = 0; j < 6; j++) {
49+
if (j == bottomIdx || j == topIdx) continue;
50+
sideMax = Math.max(sideMax, dice[i][j]);
51+
}
52+
53+
sideSum += sideMax;
54+
curBottom = topNum;
55+
}
56+
57+
return sideSum;
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)