Skip to content

Commit 5dc5c6c

Browse files
authored
[20250204] BOJ / 골드5 / 주사위 쌓기 / 설진영
1 parent 5a47453 commit 5dc5c6c

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
private static int SIZE;
7+
private static final int[] crossIndexes = {5, 3 ,4 ,1, 2, 0};
8+
9+
public static void main(String[] args) throws Exception {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
SIZE = Integer.parseInt(br.readLine());
12+
Dice[] dices = new Dice[SIZE];
13+
14+
int answer = 0;
15+
16+
StringTokenizer st;
17+
for (int i = 0; i < SIZE; i++) {
18+
st = new StringTokenizer(br.readLine());
19+
dices[i] = new Dice(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()) ,Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
20+
}
21+
22+
for (int i = 0; i < 6; i++) {
23+
int partialMax = dices[0].getSideMaxByIndex(i);
24+
int nextTopValue = dices[0].getTopValueByIndex(i);
25+
for (int j = 1; j < SIZE; j++) {
26+
partialMax += dices[j].getSideMaxByValue(nextTopValue);
27+
nextTopValue = dices[j].getTopValueByVlaue(nextTopValue);
28+
}
29+
30+
answer = Math.max(partialMax, answer);
31+
}
32+
33+
System.out.println(answer);
34+
}
35+
36+
37+
public static class Dice {
38+
int[] numbers;
39+
public Dice(int ...numbers) {
40+
this.numbers = numbers;
41+
}
42+
43+
public int getSideMaxByValue(int bottomValue) {
44+
int max = 0;
45+
int topValue = getTopValueByVlaue(bottomValue);
46+
for (int i = 0; i < 6; i++) {
47+
if (numbers[i] == bottomValue || numbers[i] == topValue) continue;
48+
max = Math.max(max, numbers[i ]);
49+
}
50+
return max;
51+
}
52+
53+
public int getSideMaxByIndex(int bottomIndex) {
54+
int max = 0;
55+
int topValue = getTopValueByVlaue(numbers[bottomIndex]);
56+
for (int i = 0; i < 6; i++) {
57+
if (numbers[i] == numbers[bottomIndex] || numbers[i] == topValue) continue;
58+
max = Math.max(max, numbers[i]);
59+
}
60+
return max;
61+
}
62+
63+
public int getTopValueByVlaue(int bottomValue) {
64+
for (int i = 0; i < 6; i++) {
65+
if (numbers[i] == bottomValue) {
66+
return getTopValueByIndex(i);
67+
}
68+
}
69+
70+
return -1;
71+
}
72+
73+
public int getTopValueByIndex(int bottomIndex) {
74+
return numbers[crossIndexes[bottomIndex]];
75+
}
76+
}
77+
}
78+
79+
```

0 commit comments

Comments
 (0)