Skip to content

Commit 9c9129c

Browse files
committed
[20260301] BOJ / G5 / 주사위 쌓기 / 김민진
1 parent a3b171a commit 9c9129c

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_2116_주사위_쌓기 {
6+
7+
private static final int[] pairs = new int[] { 5, 3, 4, 1, 2, 0 };
8+
9+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
private static StringTokenizer st;
12+
13+
private static int N, ans;
14+
private static int[][] dices, diceIdx;
15+
16+
public static void main(String[] args) throws IOException {
17+
init();
18+
sol();
19+
}
20+
21+
private static void init() throws IOException {
22+
N = Integer.parseInt(br.readLine());
23+
24+
dices = new int[N][6];
25+
diceIdx = new int[N][7];
26+
for (int i = 0; i < N; i++) {
27+
st = new StringTokenizer(br.readLine());
28+
for (int j = 0; j < 6; j++) {
29+
dices[i][j] = Integer.parseInt(st.nextToken());
30+
diceIdx[i][dices[i][j]] = j;
31+
}
32+
}
33+
}
34+
35+
private static void sol() throws IOException {
36+
findDice(0);
37+
38+
bw.write(ans + "");
39+
bw.flush();
40+
bw.close();
41+
br.close();
42+
}
43+
44+
private static void findDice(int num) {
45+
if (num == 6) {
46+
return;
47+
}
48+
49+
int sum = 0;
50+
if (num == 0 || num == 5) {
51+
sum += findMax(0, 0, 5);
52+
} else if (num == 1 || num == 3) {
53+
sum += findMax(0, 1, 3);
54+
} else if (num == 2 || num == 4) {
55+
sum += findMax(0, 2, 4);
56+
}
57+
58+
int prev = num;
59+
for (int i = 1; i < N; i++) {
60+
int cur = diceIdx[i][dices[i - 1][prev]];
61+
sum += findMax(i, cur, pairs[cur]);
62+
prev = pairs[cur];
63+
}
64+
65+
ans = Math.max(ans, sum);
66+
67+
findDice(num + 1);
68+
}
69+
70+
private static int findMax(int idx, int up, int down) {
71+
int max = Math.max(dices[idx][up], dices[idx][down]);
72+
int min = Math.min(dices[idx][up], dices[idx][down]);
73+
74+
if (max != 6) return 6;
75+
if (min != 5) {
76+
return 5;
77+
} else {
78+
return 4;
79+
}
80+
}
81+
82+
}
83+
```

0 commit comments

Comments
 (0)